WCF异步调用 - 在事件处理程序中的异常

时间:2011-12-02 16:39:07

标签: wcf icallbackeventhandler asynchronous-wcf-call

WCF异步调用 - eventhandler的异常

我正在使用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 个答案:

答案 0 :(得分:1)

你的绑定安全vindig错误。您必须切换到http(由于服务器设置可能不能),或者您应该在客户端绑定配置中切换到传输安全性。