簡體   English   中英

使用nettcp異常自托管wcf

[英]Self hosting wcf with nettcp exception

每當嘗試連接到我自己的wcf時,我都會收到超時異常。

這是配置我有:

<configuration>
  <system.serviceModel>        
    <behaviors>
        <serviceBehaviors>
            <behavior name="MetaBehaviour">
                <serviceMetadata />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="MetaBehaviour" name="WcfStreaming.LargeDataService">
            <clear />
            <endpoint address="net.tcp://localhost/LargeData" binding="netTcpBinding"
                name="Tcp" contract="WcfStreaming.ILargeDataService" listenUriMode="Explicit" />
            <endpoint address="net.tcp://localhost/LargeData/mex" binding="mexTcpBinding"
                name="TcpMex" contract="IMetadataExchange" listenUriMode="Explicit" />
            <endpoint address="http://localhost/wcfstreaming" binding="basicHttpBinding"
                bindingConfiguration="" name="BasicHttp" contract="WcfStreaming.ILargeDataService" />
        </service>
     </services>
  </system.serviceModel>
</configuration>

這里是托管代碼:

 host = new ServiceHost(typeof(WcfStreaming.LargeDataService),
           new Uri[] { HttpUri, TcpUri });

 host.Open();

 var factory = new ChannelFactory<WcfStreaming.ILargeDataService>(new NetTcpBinding(), new EndpointAddress(TcpUri)); //  Hnew NetTcpBinding(), new EndpointAddress(TcpUri));

 srvChannel = factory.CreateChannel();

 using (OpenFileDialog dlg = new OpenFileDialog())
 {
    if (dlg.ShowDialog() == DialogResult.OK)
    {
       Stream str = srvChannel.GetFile(dlg.FileName); //Exception here

       StreamReader sr = new StreamReader(str);
       string bf = sr.ReadToEnd();
       File.WriteAllText(@"C:\test", bf);
    }
 }

我討厭:

發送到net.tcp:// localhost / LargeData的此請求操作未在配置的超時(00:01:00)內收到回復。 分配給此操作的時間可能是較長超時的一部分。 這可能是因為服務仍在處理操作,或者因為服務無法發送回復消息。 請考慮增加操作超時(通過將通道/代理強制轉換為IContextChannel並設置OperationTimeout屬性)並確保該服務能夠連接到客戶端。

你可以通過在app.config文件中放置以下內容來添加wcf跟蹤(調用你的wcf服務的項目,而不是wcf服務app.config文件)。 跟蹤轉儲到c:\\ wcf.svclog

<system.diagnostics>
      <sources>
        <source name="System.ServiceModel"
                switchValue="Information, Warning, ActivityTracing, Error, Critical"
                propagateActivity="true">
          <listeners>
            <add name="traceListener"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData= "c:\wcf.svclog" />
          </listeners>
        </source>
      </sources>
    </system.diagnostics>

此外,如果它在VS下運行,但不在其外部,則表示您創建的服務主機與app.config文件中定義的服務端點不匹配(同樣是調用wcf的項目的配置文件,而不是wcf的應用程序。配置文件)。 或者,servicehost實例化代碼永遠不會運行。

它在VS下運行因為VS默認情況下創建一個WCF調試主機,它加載你的wcf服務並公開服務和MEX url。 如果應用程序崩潰,有時這個調試輔助工具會繼續運行。 該過程是wcfsvchost.exe。

“Mex”允許您獲取服務上的元數據,因此最終程序不需要它。

暫無
暫無

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

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