调用Wcf函数时中止套接字连接

时间:2017-05-29 15:06:35

标签: c# wcf

我正在尝试通过WCF服务获取对象列表。一些简单的方法工作正常。但是当我试图获取对象列表时

我收到以下错误。

错误:套接字连接已中止。这可能是由于处理消息的错误或远程主机超出接收超时或基础网络资源问题引起的。本地套接字超时为'00:59:59.9949990'。 错误:远程主机

强制关闭现有连接

这是客户端配置

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ISurveyService" sendTimeout="00:05:00"
          maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000">
          <readerQuotas maxDepth="32" maxStringContentLength="200000000"
            maxArrayLength="200000000" />
        </binding>
        <binding name="NetTcpBinding_ISurveyService1" />
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8523/SurveyService" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_ISurveyService" contract="SurveyApp.SurveyService.ISurveyService"
        name="NetTcpBinding_ISurveyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:8523/SurveyService" binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding_ISurveyService1" contract="ServiceReference.ISurveyService"
        name="NetTcpBinding_ISurveyService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

这是服务库配置:

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ISurveyService" openTimeout="00:10:00"
                   closeTimeout="00:10:00"
                   sendTimeout="00:10:00"
                   receiveTimeout="00:10:00"
                 maxReceivedMessageSize="20000000"
                  maxBufferSize="20000000"
                  maxBufferPoolSize="20000000">
          <readerQuotas maxDepth="32"
                   maxArrayLength="200000000"
                   maxStringContentLength="200000000" />
        </binding>

      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
        name="SurveyApp.SurveyService.SurveyService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISurveyService"
          contract="SurveyApp.SurveyService.ISurveyService" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange"  />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8523/SurveyService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

这是我的服务合同:

 [ServiceContract]
    public interface ISurveyService
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        IEnumerable<Question> GetAllQuestions();

        [OperationContract]
        Test GetElement();
    }

这是数据合同类

   public partial class Question
    {

        public Question()
        {
            this.QuestionOptions = new HashSet<QuestionOption>();
        }

        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public virtual ICollection<QuestionOption> QuestionOptions { get; set; }
    }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

QuestionOption类有一个类型为Question的成员,因此在序列化期间有一个递归调用,因此会发生超时。