2011-12-02 137 views
0

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

我使用eventhandler對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; 
      } 
     } 
    } 

回答

1

你的錯個安全vindig捆綁。您必須切換到http(您可能無法通過服務器設置),或者您應該切換到在客戶端綁定配置中傳輸安全性。

+0

您的意思是安全模式=「傳輸」。我已經有了這個設置.. – CoolArchTek