WCF:将程序配置转换为app.config

问题描述

| 我有以下工作程序配置(服务器端)
using (ServiceHost host = new ServiceHost(
                typeof(RequestHandler),new Uri[] { new Uri(\"net.pipe://localhost\") }))
        {
            NetNamedPipeBinding tBinding = new NetNamedPipeBinding();


            host.AddServiceEndpoint(typeof(RequestInterface),tBinding,\"Request\");

            host.open();
            Application.Run(new Form1());

        }
试图将其转换为ѭ1的代码
    <system.serviceModel>
<bindings>
  <netNamedPipeBinding>
    <binding
             closeTimeout=\"00:01:00\"
             openTimeout=\"00:01:00\"
             receiveTimeout=\"00:10:00\"
             sendTimeout=\"00:01:00\"
             transactionFlow=\"false\"
             transferMode=\"Buffered\"
             transactionProtocol=\"OleTransactions\"
             hostNameComparisonMode=\"StrongWildcard\"
             maxBufferPoolSize=\"524288\"
             maxBufferSize=\"65536\"
             maxConnections=\"10\"
             maxReceivedMessageSize=\"65536\">
      <security mode=\"Transport\">
        <transport protectionLevel=\"EncryptAndSign\" />
      </security>
    </binding>

  </netNamedPipeBinding>
</bindings>

<services>
  <service name=\"ServerApp.RequestHandler\">
    <host>
      <add baseAddress=\"net.pipe://localhost/\" />
    </host>
      <endpoint address=\"net.pipe://localhost/Request/\"
              binding=\"netNamedPipeBinding\"
              contract=\"AppLib.RequestInterface\" />
  </service>
</services>
但是,这似乎不起作用-即客户端无法连接到该服务器。 我的app.config代码有问题吗? 还是我必须以编程方式告诉.NET使用app.config中的配置?     

解决方法

否,除了根据服务类型在配置中正确分配类型/名称外,这看起来好像已经正确完成,您无需执行任何其他操作即可指向配置。 我没有解析配置,但是说实话,您可能应该使用配置编辑器工具来设置服务。这可能是导致您的服务无法正常工作的最小的小错误,错误输入或遗漏的设置。我经常说XML可能是人类可读的,但是很少有人可以编辑...而且IMO WCF配置也属于这一阵营:-)     ,我认为添加metadatexchange的mex端点可能会解决此问题,虽然不确定,但请尝试一次。 或更好地帮助您找到确切的问题。