0

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: Unable to read data from the transport connection: 一个现有的连接被远程主机强行关闭。---> 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;
            }
        }
    }
4

1 回答 1

1

您对绑定有错误的安全保护。您必须切换到 http(由于服务器设置,您可能无法切换),或者您应该切换到客户端绑定配置中的传输安全性。

于 2011-12-02T20:53:27.480 回答