【问题标题】:Silverlight WCF Service Reference "The given key was not present in the dictionary"Silverlight WCF 服务参考“字典中不存在给定的键”
【发布时间】:2011-06-01 15:05:17
【问题描述】:

问题:

我在 Silverlight 应用程序上有一个带有参考 (.net 3.5) 的 WCF 测试服务,当我创建实例时

ServiceReference1.Service1Client client = new Service1Client();

我有以下错误:

“给定的键不在字典中。”

服务是正确的,在 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>

在非 silverlight 应用程序中,参考工作就像一个 sharm....有一些解决它的想法吗?

PS:该服务是默认服务:

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

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

更多信息

{System.Collections.Generic.KeyNotFoundException:给定的键不在字典中。 在 System.ThrowHelper.ThrowKeyNotFoundException() 在 System.Collections.Generic.Dictionary2.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.ChannelFactory1..ctor(字符串端点配置名称,端点地址远程地址) 在 System.ServiceModel.EndpointTrait1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait1.CreateChannelFactory() 在 System.ServiceModel.ClientBase1.CreateChannelFactoryRef(EndpointTrait1 端点特征) 在 System.ServiceModel.ClientBase1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase1..ctor() 在 SilverlightApplication2.ServiceReference1.Service1Client..ctor() 在 SilverlightApplication2.MainPage.MainPage_Loaded(对象发送者,RoutedEventArgs e) 在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,委托 handlerDelegate,对象发送者,对象参数) 在 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}

【问题讨论】:

  • 你能显示完整的堆栈跟踪吗?或者更多 .config 信息?

标签: silverlight wcf service


【解决方案1】:

在应该定义服务的 web.config 中,您有一个 client> 配置部分 - 这不会帮助您从Silverlight 项目。

您需要在 SL 文件 ServiceReferences.ClientConfig 上定义客户端。

还有一点,SL 不支持 WSHttpBinding,所以你拥有的客户端定义不适用于 SL。

当您在 SL 项目中使用添加服务引用来创建对服务的引用时,应创建 ServiceReferences.ClientConfig 文件。如果服务使用了不受支持的绑定,那么该工具应该会给您一个错误/警告。

【讨论】:

  • 更改为 basichttpbinding 服务参考效果很好,谢谢您
【解决方案2】:

我也遇到了同样的问题,浪费了 3 天后解决了, 这是因为windows phone的silverlight不支持wsHttpBinding,所以你把服务改成basicHttpBinding就可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2012-02-18
    • 1970-01-01
    相关资源
    最近更新 更多