2012-09-26 137 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”,如错误中所示。

相关问题