将大型数据集发送到WCF服务会产生协议异常

时间:2013-04-18 14:08:14

标签: c# wcf dataset

我有一个wpf应用程序,它发送的DataSet差不多有25 DataTable。我无法使用同步和异步两者来修复The remote server returned an unexpected response: (400) Bad Request。以下是app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ICommunication" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                  <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                   maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />    
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:49486/Communication.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICommunication"
                contract="CommunicationReference.ICommunication" name="BasicHttpBinding_ICommunication" />
        </client>
    </system.serviceModel>
</configuration>

这是Service的web.config:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147483647" executionTimeout="10000"/>
  </system.web>
  <connectionStrings>
    <add name="conName" connectionString="Data Source=*******;Initial Catalog=****; User ID=**; Password=*****"/>  

  </connectionStrings>
  <system.serviceModel>   

    <behaviors>      
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 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="false"/>
          <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="1000" maxConcurrentInstances="1600" />
        </behavior>
      </serviceBehaviors>
    </behaviors>    
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

P.S。:我通过传递空白DataSet来测试它,它的工作原理。但是DataSet DataTable无效。

1 个答案:

答案 0 :(得分:0)

我已将整个服务模型包含在您的参考中,请将我设置为 LargeDataService 的合约设置为相应的界面

<system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
        <bindings>
            <basicHttpBinding>
                <binding name="LargeDataBinding" maxReceivedMessageSize="4194304">
                    <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
                </binding>
            </basicHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="webBehavior" name="serviceEndpoints">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeDataBinding" behaviorConfiguration="customBehavior" contract="LargeDataService"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="webBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                    <dataContractSerializer maxItemsInObjectGraph="2147483646" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="customBehavior">
                    <webHttp automaticFormatSelectionEnabled="false" helpEnabled="true"/>
                    <dataContractSerializer maxItemsInObjectGraph="2147483646" />
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>