簡體   English   中英

WCF異步調用-事件處理程序上的異常

[英]WCF Asynchronous Call - Exception at eventhandler

WCF異步調用-事件處理程序上的異常

我正在使用事件處理程序對WCF方法進行異步調用。 我在“ EventAddCallback”事件中遇到錯誤,並且“ e.Error”顯示以下錯誤。 知道為什么嗎? 我添加了示例代碼,錯誤信息,跟蹤信息和我嘗試過的選項。

System.Reflection.TargetInvocationException:操作期間發生異常,使結果無效。 檢查InnerException以獲取異常詳細信息。 ---> System.ServiceModel.CommunicationException:收到對https://demosite.com/ourservice.asmx的HTTP響應時發生錯誤。 這可能是由於服務端點綁定未使用HTTP協議。 這也可能是由於服務器終止了HTTP請求上下文(可能是由於服務關閉了)。 有關更多詳細信息,請參見服務器日志。 ---> System.Net.WebException:基礎連接已關閉:接收時發生意外錯誤。 ---> System.IO.IOException:無法從傳輸連接中讀取數據:現有連接被遠程主機強行關閉。 ---> System.Net.Sockets.SocketException:現有的連接被遠程主機強行關閉

我啟用了跟蹤並顯示了。

System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
An error occurred while receiving the HTTP response to https://demosite.com/ourservice.asmx. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
-->System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-->The underlying connection was closed: An unexpected error occurred on a receive.
------>System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
------>Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---------->System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
---------->An existing connection was forcibly closed by the remote host


Options I tried..
1. Increased 
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>

2. Enabled 'Keep Alive', increased buffer size(s)
<httpsTransport maxReceivedMessageSize="2147483647" keepAliveEnabled="true" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" />              

3. added endpointBehaviors

      <endpointBehaviors>
        <behavior name="demo">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>

    class Program
    {
        static ManualResetEvent closeapp = new ManualResetEvent(false);
        static void Main(string[] args)
        {
            wcfclient.AddCompleted += new EventHandler<AddCompletedEventArgs>(EventAddCallback);
            wcfclient.AddAsync(employees);
            closeapp.WaitOne(); 
        }
        static void EventAddCallback(object sender, AddCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    wcfclient.Close();
                    closeapp.Set(); 
                }else
                {
                   //Continue with other calls.
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }
    }

您對綁定的安全性有誤。 您必須切換到http(可能由於服務器設置而可能無法使用),或者應該在客戶端綁定配置中切換到Transport Security。

暫無
暫無

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

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