2012-01-11 164 views
3

在我的客户端应用程序,我发现了以下错误:WCF - 客户端点配置错误

Could not find endpoint element with name 'QueuedService' and contract 
'IMyService' in the ServiceModel client configuration section. This might 
be because no configuration file was found for your application, or because no 
endpoint element matching this name could be found in the client element. 

我用svutil.exe生成我使用的客户端代理。通常我的手,推出自己的代理,然后我注意到了界面的服务合同所产生的版本没有命名空间中的我原来在服务合同中规定:

// Auto-generated proxy 

namespace MyServices.Contracts 
{ 
    // Request object in correct namespace 

    [System.Runtime.Serialization.DataContractAttribute(
     Name="MyRequest", 
     Namespace="http://schemas.datacontract.org/2004/07/MyServices.Contracts")] 
    public class MyRequest 
    { 
     // ... 
    } 
} 

// Service contract NOT in namespace 

[System.ServiceModel.ServiceContractAttribute(
    ConfigurationName="IMyService")] 
public interface IMyService 
{ 
    // ... 
} 

我的主机应用程序的web.config指定服务端点(一个用于MSMQ和一个TCP):

<system.serviceModel> 
<service> 

<!-- etc... -->  

<endpoint name="QueuedService" 
      address="net.msmq://localhost/private/MyQueue" 
      binding="netMsmqBinding" 
      bindingConfiguration="MsmqDefaultBinding_Local" 
      contract="MyService.Contracts.IMyService" /> 
<endpoint name="TcpService" 
      address="net.tcp://localhost/ServiceHost/TheService.svc" 
      contract="MyServices.Contracts.IMyService" 
      binding="netTcpBinding" 
      bindingConfiguration="netTcpWindowsBinding" /> 
</service> 
</system.serviceModel> 

客户端应用程序使用的服务是这样的:

var endpointConfigName = GetEndpointConfigNameFromConfig(); 

using(var myServiceClient = new MyServiceClient(endpointConfigName)) 
{ 
    // Create Request object... 

    // Call service like so: 

    myServiceClient.SomeServiceMethod(requestObject); 
} 

和客户端的web.confi g:

<client> 
    <endpoint name="QueuedService" 
      address="net.msmq://localhost/private/MyQueue" 
      binding="netMsmqBinding" 
      bindingConfiguration="MsmqDefaultBinding_Local" 
      contract="MyServices.Contracts.IMyService" /> 
    <endpoint name="TcpService" 
      address="net.tcp://localhost/ServiceHost/TheService.svc" 
      contract="MyServices.Contracts.IMyService" 
      binding="netTcpBinding" 
      bindingConfiguration="netTcpWindowsBinding" /> 
</client> 

任何想法?

+0

错误似乎与客户端配置文件。你确定客户端应用程序有一个与它关联的app.config吗? – 2012-01-11 06:58:56

+0

TCP端点是否工作? – 2012-01-11 08:16:07

+0

你能发布完整的客户端配置和服务接口吗? – Rajesh 2012-01-11 09:25:53

回答

3

看起来像生成的代理中的ConfigurationName只是IMyService而不是MyServices.Contracts.IMyService。因此,在您的客户端web.config中,您可以将合同作为IMyService而不是完整的合同,然后测试它是否有效。

1

这有点琐碎,但你的app.config与应用程序运行的过程相关吗?例如,如果您在汇编/单独项目中创建了服务引用,但是从引用该程序集的exe中调用它,则配置需要位于客户端exe中的app.config中,而不是程序集的app.config中。