【问题标题】:WCF - Client Endpoint Configuration ErrorWCF - 客户端端点配置错误
【发布时间】:2012-02-07 12:37:05
【问题描述】:

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

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>

有什么想法吗???

【问题讨论】:

  • 错误似乎与客户端配置文件有关。您确定客户端应用程序有与之关联的 app.config 吗?
  • 你能发布完整的客户端配置和你的服务接口吗?
  • 此外,当您尝试调用服务时,您必须有一些代码,例如 myservice_client obj = new myservice_client();如果这是您在客户端中拥有的代码,那么您需要将其设置为 myservice_client obj = new myservice_client("QueuedService");
  • @Rajesh。是的,您的第二个示例是如何实例化客户端。我将编辑我的问题以包含正在使用的实际代码
  • 似乎生成的代理中的 ConfigurationName 只是 IMyService 而不是 MyServices.Contracts.IMyService。因此,在您的客户 web.config 中,您是否可以将合同作为 IMyService 而不是强制合同并测试它是否有效。

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2014-05-12
      • 2011-05-03
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多