简体   繁体   English

Silverlight WCF 服务参考“字典中不存在给定的键”

[英]Silverlight WCF Service Reference “The given key was not present in the dictionary”

Question:问题:

I Have a WCF test Service with a reference (.net 3.5) on Silverlight application and when i make an instance我有一个 WCF 测试服务,在 Silverlight 应用程序上有一个参考(.net 3.5),当我创建一个实例时

ServiceReference1.Service1Client client = new Service1Client();

i have the following error:我有以下错误:

"The given key was not present in the dictionary." “给定的键不在字典中。”

The service is correct and in web.config i have something like this服务是正确的,在 web.config 我有这样的东西

<client>
        <endpoint address="http://localhost:49955/Service1.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
</client>

In a NON silverlight application reference works like a sharm....some ideas to fix it?在 NON silverlight 应用程序参考中的工作就像一个 sharm....一些想法来解决它?

PS: the service is a default service: PS:该服务是默认服务:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    void DoWork();
}

public class Service1 : IService1
{
    public void DoWork()
    {
    }
}

MORE INFO更多信息

{System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. {System.Collections.Generic.KeyNotFoundException:字典中不存在给定的键。 at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary 2.get_Item(TKey key) at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client() at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory 1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.EndpointTrait 1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait 1.CreateChannelFactory() at System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1 endpoi在 System.ThrowHelper.ThrowKeyNotFoundException() 在 System.Collections.Generic.Dictionary 2.get_Item(TKey key) at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client() at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard) at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) at System.ServiceModel.ChannelFactory 1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) 在 System.ServiceModel.EndpointTrait 1.CreateSimplexFactory( 1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait 1.CreateChannelFactory() 在 System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1端点ntTrait) at System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase 1..ctor() at SilverlightApplication2.ServiceReference1.Service1Client..ctor() at SilverlightApplication2.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} ntTrait) 在 System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase 1..ctor() 在 SilverlightApplication2.ServiceReference1.Service1Client..ctor() 在 SilverlightApplication2.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e) 在MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}

In web.config, which is where the service is supposed to be defined, you have a <system.serviceModel/ client > config section - this won't help you define the client from the Silverlight project.在应该定义服务的 web.config 中,您有一个 <system.serviceModel/ client > 配置部分 - 这不会帮助您从 Silverlight 项目定义客户端。

You need a client definition on the SL file ServiceReferences.ClientConfig.您需要 SL 文件 ServiceReferences.ClientConfig 上的客户端定义。

One more thing, SL doesn't support WSHttpBinding, so that client definition which you have will not work for SL.还有一件事,SL 不支持 WSHttpBinding,因此您拥有的客户端定义不适用于 SL。

The ServiceReferences.ClientConfig file should be created when you use the Add Service Reference in your SL project to create a reference to the service.当您在 SL 项目中使用 Add Service Reference 创建对服务的引用时,应创建 ServiceReferences.ClientConfig 文件。 If the service uses a binding which is not supported, then the tool should give you an error / warning.如果服务使用不受支持的绑定,则该工具应该会给您一个错误/警告。

I have faced the same issue and was able to solve it after wasting 3 days, It is because silverlight for windows phone doesn't support wsHttpBinding, so your change you service to basicHttpBinding and it will work我也遇到了同样的问题,浪费了 3 天就解决了,这是因为 windows 手机的 silverlight 不支持 wsHttpBinding,所以您将服务更改为 basicHttpBinding 并且它将起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM