WCF 4 - 当从服务返回DataTable时,远程主机强制关闭现有连接

时间:2013-06-06 06:50:50

标签: wcf

我的服务有一个返回DataTable的OperationContract。每当我从这里进入, 服务器错误显示“现有连接被远程主机强行关闭”

在服务方的IServie1.svc中,

[ServiceContract]
public interface IService1
{
    [OperationContract]
    bool HandShake(int branchId);

    [OperationContract]
    Investigation Synchronize(string tblName);

    [OperationContract]
    DataTable Synchronize1(string tblName);

在我的客户端代码中,

        Service1Client client = new Service1Client();

        GridView1.DataSource = client.Synchronize1("inv");

        GridView1.DataBind();

在服务的Web.config中,

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basic1" maxReceivedMessageSize="2147483647">
      <readerQuotas maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>

</bindings>
<services>
  <service name="WcfService2.Service1" behaviorConfiguration="Service1Behavior">
    <endpoint
       address=""
        binding="basicHttpBinding"
        contract="WcfService2.IService1"
        bindingConfiguration="basic1"></endpoint>
    <endpoint
       address="Add2"
        binding="wsHttpBinding"
        contract="WcfService2.IService1"></endpoint>
    <endpoint
       address="mex"
       binding="mexHttpBinding"
        contract="IMetadataExchange"></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/WcfService2/Service1.svc"/>
      </baseAddresses>
    </host>
  </service>

</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

在客户端的Web.config中,

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647">
      <readerQuotas maxStringContentLength="2147483647" />
    </binding>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/WcfService2/Service1.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
  <!--<endpoint address="http://localhost/WcfService2/Service1.svc/Add2"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
    <identity>
      <servicePrincipalName value="host/Jenny-PC" />
    </identity>
  </endpoint>-->
</client>

1 个答案:

答案 0 :(得分:1)

返回DataTable并不总是做Web服务的最佳实践,消费者不使用.NET进行映像,他们如何序列化消息,他们的语言中DataTable的对应部分是什么,等等等等。

关于你的问题,我认为你应该添加诊断信息,以便能够看到确切发生的事情: 将以下部分添加到serviceModel

<diagnostics>
    <messageLogging
       logEntireMessage="true"
       logMalformedMessages="false"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="300000"
       maxSizeOfMessageToLog="2000000"/>
  </diagnostics>

此部分为app.config或web.config的第1级

<system.diagnostics>
<trace autoflush="true" />
<sources>
  <source name="System.ServiceModel"
          switchValue="Information, ActivityTracing"
          propagateActivity="true">
    <listeners>
      <add name="sdt"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\SdrConfigExample.e2e"  />
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
      <add name="messages"
      type="System.Diagnostics.XmlWriterTraceListener"
      initializeData="c:\messages.svclog" />
    </listeners>
  </source>
</sources>

当你发现时,请告诉我们;)