2012-09-26 65 views
0

創建WCF服務客戶端對象時遇到問題。Silverlight WCF服務客戶端實例化

HelloServiceClient helloWorldClient = new HelloServiceClient(「BasicHttpBinding_IDataAccess」);

這裏是我的ServiceReferences.ClientConfig的內容

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IDataAccess" maxBufferSize="2147483647" 
      maxReceivedMessageSize="2147483647"> 
      <security mode="None" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8732/Design_Time_Addresses/HelloWcf/Service1/mex" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IDataAccess" contract="IHelloService" 
      name="BasicHttpBinding_IDataAccess" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

的錯誤消息是如下

System.InvalidOperationException:無法與 名 'BasicHttpBinding_IDataAccess' 和合同 「找到終結點元素ServiceModel客戶端 配置部分中的ServiceReference1.IHelloService'。這可能是因爲沒有爲您的應用程序找到配置文件 ,或者因爲在客戶端元素中找不到此名稱匹配的端點元素 。在 System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint,字符串configurationName)在 System.ServiceModel.ChannelFactory.ApplyConfiguration(字符串 configurationName)在 System.ServiceModel.ChannelFactory.InitializeEndpoint(字符串 configurationName,的EndpointAddress地址)在 System.ServiceModel.ChannelFactory 1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) at System.ServiceModel.EndpointTrait 1.CreateSimplexFactory()在 System.ServiceModel.EndpointTrait 1.CreateChannelFactory() at System.ServiceModel.ClientBase 1.CreateChannelFactoryRef(EndpointTrait 1 endpointTrait) at System.ServiceModel.ClientBase 1.InitializeChannelFactoryRef()在 System.ServiceModel.ClientBase`1..ctor(字符串 endpointConfigurationName)在 SilverlightApplication1.ServiceReference1.HelloServiceClient..ctor(字符串 endpointConfigurationName)在 SilverlightApplication1.MainPage.Button_Click(對象發件人, RoutedEventArgs E)

有人能幫助我在這個問題?並請讓我知道如果你想要任何其他代碼/配置。

+0

是不是你的契約名稱需要是'ServiceReference1.IHelloService',將配合我的文件。 VS會自動爲你生成它們 – BugFinder

+0

這很有效。非常感謝。 – Alvin

+0

請在下面標記正確的答案 - 它有助於您的代表並使網站正常工作 – BugFinder

回答

0

如上所示 - 合同名稱需要爲「ServiceReference1.IHelloService」,如錯誤中所示。

相關問題