WCF ServiceHost关闭操作超时

时间:2015-04-07 18:21:00

标签: c# asp.net wcf

我有这个巨大的超时问题,我不知道如何解决它! 我正在使用Windows服务客户端通过 HTTPS

连接到WCF服务

我看过这个: http://blogs.msdn.com/b/hongmeig/archive/2010/03/06/timeouts-in-wcf-and-their-default-values.aspx

服务器端生成错误

  

ServiceHost关闭操作在00:00:10后超时。这可以   是因为客户端无法关闭其中的会话通道   所需的时间。分配给此操作的时间可能是a   超时的一部分。

在客户端生成错误:

System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

Server stack trace: 
   at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.System.IDisposable.Dispose()

这是我对WCF服务的绑定:

  <bindings>
    <wsHttpBinding>
      <binding name="Binding1" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" />
        <security mode="TransportWithMessageCredential">
          <message clientCredentialType="UserName" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>

这是代码客户端:

        wsHttpBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential)
       {
           CloseTimeout = new TimeSpan(0, 0, 10, 0),
           OpenTimeout = new TimeSpan(0, 0, 10, 0),
           ReceiveTimeout = new TimeSpan(0, 10, 0, 0),
           SendTimeout = new TimeSpan(0, 0, 10, 0),
           TransactionFlow = false,
           MaxBufferPoolSize = 524288,
           MaxReceivedMessageSize = 2147483647,
           ReaderQuotas =
           {
               MaxDepth = 128,
               MaxStringContentLength = int.MaxValue,
               MaxArrayLength = 2147483647,
               MaxBytesPerRead = 16384,
               MaxNameTableCharCount = 16384
           }
       };

        wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

        wsHttpBinding.ReliableSession.Ordered = true;
        wsHttpBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 0, 10, 0);
        wsHttpBinding.ReliableSession.Enabled = true;
        Ednpoint = new EndpointAddress(new Uri(URL));

        myChannelFactory = new ChannelFactory<IPoint>(wsHttpBinding, Ednpoint);
        myChannelFactory.Endpoint.Contract.SessionMode = SessionMode.Allowed;

        ClientCredentials cc = myChannelFactory.Endpoint.Behaviors.Find<ClientCredentials>();

        cc.UserName.UserName = usr;
        cc.UserName.Password = pass;
        myChannelFactory.CreateChannel();

我正在使用此代码发送如下数据:

            using (IClientChannel client = (IClientChannel)myChannelFactory.CreateChannel())
            {
                client.OperationTimeout = TimeSpan.FromMinutes(10);
                IPoint wcfClient1 = (IPoint)client;
                for (int start = startpos; start < totalSize; start += size)
                {
                    List<Point> send = r.Skip(start).Take(size).ToList();
                    xreturn = wcfClient1.Update(send);
                    counter += 1;
                }
            }

1 个答案:

答案 0 :(得分:0)

我已经解决了应用程序池在托管服务器上不断重启的问题。