简体   繁体   English

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

[英]WCF: transform programmatic configuration into app.config

I have the following working programmatic configuration (server-side)我有以下工作编程配置(服务器端)

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());

        }

trying to turn this into code for app.config :试图把它变成app.config的代码:

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

However, this doesn't seem to work - ie clients can not connect to this.但是,这似乎不起作用 - 即客户端无法连接到此。

Do I have something wrong in my app.config code?我的 app.config 代码有问题吗? Or do I have to something programmatically to tell .NET to use the configuration from app.config?还是我必须以编程方式告诉 .NET 使用 app.config 中的配置?

No, aside from properly assigning the type/name in the config based on the service type... which it looks like you've done correctly, you shouldn't have to do anything else to point to the configuration.不,除了根据服务类型正确分配配置中的类型/名称......看起来你已经正确完成了,你不应该做任何其他事情来指向配置。

I didn't parse through the config, but honestly, you should probably use the Configuration Editor Tool to set up your service.我没有解析配置,但老实说,您可能应该使用配置编辑器工具来设置您的服务。 It's probably the smallest little error, or mistype, or missed setting that's causing your service not to work.这可能是导致您的服务无法运行的最小的小错误、错误输入或错过的设置。 I've often said that XML may be human readable, but it's rarely human editable... and IMO WCF configuration falls into that camp:-)我经常说 XML 可能是人类可读的,但它很少是人类可编辑的......而且 IMO WCF 配置属于该阵营:-)

I think adding a mex endpoint of metadatexchange may resolve this, not sure but try it once.我认为添加 metadatexchange 的 mex 端点可能会解决此问题,但不确定但尝试一次。 or its better you on the trace for service where you can find out exact problem.或者更好地跟踪服务,在那里您可以找到确切的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM