簡體   English   中英

WCF:將編程配置轉換為 app.config

[英]WCF: transform programmatic configuration into 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());

        }

試圖把它變成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>

但是,這似乎不起作用 - 即客戶端無法連接到此。

我的 app.config 代碼有問題嗎? 還是我必須以編程方式告訴 .NET 使用 app.config 中的配置?

不,除了根據服務類型正確分配配置中的類型/名稱......看起來你已經正確完成了,你不應該做任何其他事情來指向配置。

我沒有解析配置,但老實說,您可能應該使用配置編輯器工具來設置您的服務。 這可能是導致您的服務無法運行的最小的小錯誤、錯誤輸入或錯過的設置。 我經常說 XML 可能是人類可讀的,但它很少是人類可編輯的......而且 IMO WCF 配置屬於該陣營:-)

我認為添加 metadatexchange 的 mex 端點可能會解決此問題,但不確定但嘗試一次。 或者更好地跟蹤服務,在那里您可以找到確切的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM