2013-04-18 50 views
0

我有一个wpf应用程序发送一个DataSet近25 DataTable。我无法修复同步和异步的The remote server returned an unexpected response: (400) Bad Request。下面是在app.config:发送大数据集到WCF服务给出协议例外

<?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> 

,这是服务的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,其工作进行了测试。但DataSetDataTable它不能正常工作。

+0

你有你的WCF服务定义readerQuotas相同的设置?还启用跟踪(http://msdn.microsoft.com/en-us/library/ms733025.aspx)并检查跟踪文件以查看导致400错误请求异常的原因 – Rajesh

+0

您可以将服务器的代码发布到哪里返回你的数据表? – evgenyl

+0

我没有回来,我将它传递给网络服务 – Arshad

回答

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> 
+0

的工作仍然是相同的错误。 – Arshad

+0

请再次检查 –

+0

我必须在客户端或服务配置中更新吗? – Arshad