代码之家  ›  专栏  ›  技术社区  ›  Jesse Roper

WCF:套接字连接已中止

  •  3
  • Jesse Roper  · 技术社区  · 15 年前
    CommunicationException was unhandled by user code
    The socket connection was aborted. This could be caused by an error processing your message
    or a receive timeout being exceeded by the remote host, or an underlying network resource
    issue. Local socket timeout was '02:48:04.9840000'.
    

    我已经测试这个应用程序几个月了,在对其中一个服务做了一个小的更改之后,我刚刚看到这个错误。只有几秒钟,所以我不认为是超时问题。

    InnerException:System.IO.IOException:读取操作失败,请参阅InnerException

    任何建议都非常感谢!

    5 回复  |  直到 15 年前
        1
  •  4
  •   Johann Blais    15 年前

    很可能遇到配额问题,如绑定中定义的MaxReceivedMessageSize、MaxArrayLength和MaxStringContentLength。

    您还可以查看行为中可用的MaxItemsInObjectGraph属性。

        2
  •  9
  •   filmor    10 年前

    通常,当对方没有完全关闭连接时,我会看到这个错误。如果在客户端有一个继承自 ClientBase<T> 那你应该打电话 Close 客户群<T> IDisposable 所以你可以用 using

    如果你在使用 ChannelFactory<T> ICommunicationObject ;你应该打电话 当你完成的时候。

    here .

    请注意,要清楚地了解正在发生的情况,可能需要为客户端和服务设置跟踪。为了查看您将使用的痕迹 SvcTraceViewer 应该在 Program Files\Microsoft SDKs\Windows\v6.0A\bin Program Files\Microsoft SDKs\Windows\v7.0A\bin 文件夹。如果必须同时跟踪客户端和服务,可以在 SvcTraceViewer公司 使用 File / Add 菜单。

        3
  •  3
  •   C. Tewalt    10 年前

    除了在MaxReceivedMessageSize、MaxArrayLength、MaxStringContentLength、MaxItemsInObjectGraph中没有足够高的值之外,正如Johann指出的。。。

    检查以确保您正在序列化的类型能够很好地与WCF一起使用。例如,我有同样的问题,但后来意识到我正在发送 System.DBNull 通过导致服务中止的电线。一旦我过滤了 DBNull 物体出来了,一切又开始工作了。

        4
  •  2
  •   Tony    7 年前

    在我的例子中,向响应对象添加了一个枚举,但是用于填充对象的存储过程没有从数据库返回值。它返回的默认值(为零)不是创建的枚举的有效值。例如:

    using System;
    
    namespace Playground
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                Console.WriteLine((int)new SomeResponse().Enum);
                Console.ReadLine();
            }
    
            public enum SomeEnum
            {
                Value1 = 1,
                Value2 = 2,
                Value3 = 3
            }
    
            public class SomeResponse
            {
                public SomeEnum Enum { get; set; }
            }
        }
    }
    

    您将看到枚举的值为零,即使没有枚举值为零。

    如果您试图从WCF调用返回SomeResponse对象,并且该对象具有此状态,则会得到与问题中所述相同的错误。

        5
  •  0
  •   azpc    6 年前

    在我的例子中,我返回一个流,流上有一个using子句。在发送流并创建连接之前关闭流的错误。

        6
  •  0
  •   fiat    6 年前

    在我的情况下,我们有两个系统 remoteSystem 以及 clientSystem

    • 两个系统都有用于身份验证的公共/私有证书。
    • 客户端使用 dev.clientSubsystem.acme 证书

    Test-NetConnection -Port 808 -ComputerName dev.remote-system.acme-corp.net-InformationLevel Detailed
    

    原来这个错误是在客户端系统配置为使用它的私有证书进行身份验证时发生的( )但是证书不存在-或者在我们的例子中引用了错误的证书进行身份验证。

    <system.serviceModel>
       <client>
          <endpoint name="RemoteSystemService" address="net.tcp://dev.remote-system.acme-corp.net:808/service.svc" behaviorConfiguration="remoteSystemNetTcpBindingBehavior" binding="netTcpBinding" contract="AcmeCorp.RemoteSystem.IRemoteSystemService">
             <identity>
                <dns value="dev.remote-system.acme" />
             </identity>
          </endpoint>
       </client>
       <bindings>
          <netTcpBinding>
             <binding>
                <security mode="Transport">
                   <transport clientCredentialType="Certificate" protectionLevel="EncryptAndSign" />
                </security>
             </binding>
          </netTcpBinding>
       </bindings>
       <behaviors>
          <endpointBehaviors>
             <behavior name="remoteSystemNetTcpBindingBehavior">
                <clientCredentials>
                   <clientCertificate findValue="CN=dev.clientSubsystem.acme" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName" />
                   <serviceCertificate>
                      <authentication certificateValidationMode="PeerTrust" />
                   </serviceCertificate>
                </clientCredentials>
             </behavior>
          </endpointBehaviors>
       </behaviors>
    </system.serviceModel>