2011-06-01 29 views
2

問:Silverlight的WCF服務參考「給定的鍵不存在在詞典中」

我有一個WCF服務的測試與Silverlight應用程序的參考(.NET 3.5),當我做出一個實例

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應用程序中引用的作品就像一個沙姆沙伊赫....一些想法解決它?

PS:所述服務是默認服務:

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

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

MORE INFO

{System.Collections.Generic.KeyNotFoundException:給定的鍵不存在在詞典中。 在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(字符串endpointConfigurationName,的EndpointAddress remoteAddress) 在System.ServiceModel.EndpointTrait 1.CreateSimplexFactory() at System.ServiceModel.EndpointTrait 1.CreateChannelFactory() 在System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1個endpointTrait) 在System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef() at System.ServiceModel.ClientBase 1..ctor() 在SilverlightApplication2.ServiceReference1.Service1Client..ctor() 在SilverlightApplication2.MainPage.MainPage_Loaded(對象發件人,RoutedEventArgs E) 在MS.Internal。 CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,Delegate handlerDelegate,Object sender,Object args) 在MS.Internal.JoltHelper.FireEvent(IntPtr的unmanagedObj,IntPtr的unmanagedObjArgs,的Int32 argsTypeIndex,的Int32 actualArgsTypeIndex,字符串eventName的)}

+0

燦你顯示一個完整的堆棧跟蹤?或者更多的.config信息? – 2011-06-01 15:10:31

回答

1

在web.config中,這是其中服務應該被定義,則有一個< system.serviceModel/客戶端 > config部分 - 這不會幫助您從Silverlight項目定義客戶端。

您需要SL文件ServiceReferences.ClientConfig上的客戶端定義。

還有一件事,SL不支持WSHttpBinding,因此您擁有的客戶端定義將不適用於SL。

當您在SL項目中使用添加服務引用來創建對服務的引用時,應該創建ServiceReferences.ClientConfig文件。如果服務使用不支持的綁定,那麼該工具應該給你一個錯誤/警告。

+0

是的你是對的... ServiceReferences。ClientConfig是空的! – user756037 2011-06-01 15:25:17

+0

更改爲basichttpbinding服務引用很好,謝謝你 – user756037 2011-06-01 15:28:14

0

我都面臨着同樣的問題,並且能浪費3天, 這是因爲Silverlight的Windows Phone的不支持的wsHttpBinding後解決它,所以你改變你服務於basicHttpBinding的,它會工作