简体   繁体   English

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

[英]WCF Asynchronous Call - Exception at eventhandler

WCF Asynchronous Call - Exception at eventhandler WCF异步调用-事件处理程序上的异常

I am making Asynchronous call to WCF method with eventhandler. 我正在使用事件处理程序对WCF方法进行异步调用。 I am getting an error at 'EventAddCallback' event and 'e.Error' shows the following error. 我在“ EventAddCallback”事件中遇到错误,并且“ e.Error”显示以下错误。 Any knows why? 知道为什么吗? I adding sample code, error info, tracing info and options I tried.. 我添加了示例代码,错误信息,跟踪信息和我尝试过的选项。

System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. System.Reflection.TargetInvocationException:操作期间发生异常,使结果无效。 Check InnerException for exception details. 检查InnerException以获取异常详细信息。 ---> System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to https://demosite.com/ourservice.asmx . ---> System.ServiceModel.CommunicationException:收到对https://demosite.com/ourservice.asmx的HTTP响应时发生错误。 This could be due to the service endpoint binding not using the HTTP protocol. 这可能是由于服务端点绑定未使用HTTP协议。 This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). 这也可能是由于服务器终止了HTTP请求上下文(可能是由于服务关闭了)。 See server logs for more details. 有关更多详细信息,请参见服务器日志。 ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.Net.WebException:基础连接已关闭:接收时发生意外错误。 ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.IO.IOException:无法从传输连接中读取数据:现有连接被远程主机强行关闭。 ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host ---> System.Net.Sockets.SocketException:现有的连接被远程主机强行关闭

I enabled the tracing and it shows.. 我启用了跟踪并显示了。

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;
            }
        }
    }

You have th wrong security vindig for the binding. 您对绑定的安全性有误。 Either you must switch to http (which you probably can't due to server setup) or you should switch to transport Security in the client binding config. 您必须切换到http(可能由于服务器设置而可能无法使用),或者应该在客户端绑定配置中切换到Transport Security。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM