WCF - 客户端端点配置错误

时间:2012-01-11 05:13:01

标签: c# .net wcf wcf-binding wcf-client

在我的客户端应用程序中,我收到以下错误:

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.config:

<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>

任何想法???

2 个答案:

答案 0 :(得分:3)

似乎Generated代理中的ConfigurationName只是IMyService而不是MyServices.Contracts.IMyService。因此,在您的客户端web.config中,您可以将合同作为IMyService而不是完整的合同,并测试是否有效。

答案 1 :(得分:1)

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