0

我试图摆脱 WCF 项目的 app.config 文件,我需要将设置硬编码到我正在生成的 DLL 中。

我创建了我的代理类,svcUtil并且客户端在我使用时工作正常App.config

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="ManagementEndpoint">
        <security mode="None" />
      </binding>
    </netTcpBinding>
  </bindings>
  <client>
    <endpoint address="net.tcp://example.com/MyApp/DomainManagement"
        binding="netTcpBinding" bindingConfiguration="ManagementEndpoint"
        contract="MyApp.DomainManagementProxy.IDomainManagement"
        name="DomainManagementEndpoint" />
  </client>
</system.serviceModel>

但是,如果我删除我的App.config并用以下内容替换默认构造函数

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class DomainManagementClient : System.ServiceModel.ClientBase<MyApp.DomainManagementProxy.IDomainManagement>, MyApp.DomainManagementProxy.IDomainManagement
{

    public DomainManagementClient() 
        : base(new NetTcpBinding(SecurityMode.None, false), 
               new EndpointAddress("net.tcp://example.com/MyApp/DatabaseManagement"))
    {
    }

    //(Snip)

一旦我在客户端调用第一个方法,它就会给我以下错误

由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action ' http://example.com/MyApp/DomainManagement/IDomainManagement/GetServerSetup '的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

我需要更改/放入我的构造函数以使绑定正常工作吗?

4

1 回答 1

1

配置有 'net.tcp://example.com/MyApp/DomainManagement' 作为 URL。但是您的代码具有“net.tcp://example.com/MyApp/DatabaseManagement”。那可能是不匹配。

修改生成的代理不是一个好主意。但是,由于您决定对 URL 和绑定进行硬编码,因此您可以在应用程序代码中执行以下操作。

DomainManagementClient client = new DomainManagementClient(new NetTcpBinding(SecurityMode.None), new EndpointAddress("net.tcp://example.com/MyApp/DatabaseManagement"));

生成的服务代理应该自动让这个重载接受绑定和指向的地址。

于 2013-02-22T18:44:32.410 回答