“远程服务器返回一个意外的响应:(400)错误的请求”

问题描述 投票:0回答:2

我完全同意这个问题,我在moment.I有一直在阅读各种文章和博客的最后2天,使大多数的推荐变化,但我还是有这个问题难住了。

基本上我传递数组对象作为参数从客户机到该服务,然后给我的上述错误。

我可以处理200个记录确定,但如果我将它设置为250为例,它会返回400错误。我已经启用跟踪等,但没有被记录在所有的时候出现了错误。无论是客户端和服务都在相同的环境(测试)运行-windows 2008R2我会同时显示配置文件,以及如何我打电话的服务。

客户端配置

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
  </configSections>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime  executionTimeout="180" maxRequestLength="2147483647" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_FinHqclient" closeTimeout="00:25:00"
          openTimeout="00:25:00" receiveTimeout="10:50:00" sendTimeout="00:25:00"
          maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
          useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />          
          <security>
            <transport realm="" />
          </security>
        </binding>
      </wsHttpBinding>
      <basicHttpBinding>
        <binding  maxBufferPoolSize="2147483647" name="test" maxBufferSize="2147483647"  maxReceivedMessageSize="2147483647" >
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="maxItemsInObjectGraphBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <endpoint address="http://server:8123/service.svc" behaviorConfiguration="maxItemsInObjectGraphBehaviour"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_FinHqclient"    
        contract="sfgServ.FinHqclient" name="WSHttpBinding_FinHqclient">
        <identity>
          <servicePrincipalName value="host/local" />
        </identity>
      </endpoint>
    </client>    
  </system.serviceModel>
</configuration>

这是服务器配置文件:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

  </configSections>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "c:\log\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />    
<httpRuntime  executionTimeout="180" maxRequestLength="2147483647" />
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true"  logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <protocolMapping>
      <add scheme="http" binding="wsHttpBinding"/>
    </protocolMapping>
    <services>
      <service name="SFG.CRM2011.WebServiceFinHqFinHq.Service"  behaviorConfiguration="SFG.CRM2011.WebServiceFinHq.ServiceBehavior">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="SFG.CRM2011.WebServiceFinHq.BindConfig"  
                  contract="sfgServ.IClientFinHQ" behaviorConfiguration="SFG.CRM2011.WebServiceFinHq.wsServiceEndpointBehavior">
        </endpoint>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" bindingConfiguration="higherMessageSize_MEX" address="mex" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SFG.CRM2011.WebServiceFinHq.wsServiceEndpointBehavior">          
          <dataContractSerializer  maxItemsInObjectGraph="2147483646" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="SFG.CRM2011.WebServiceFinHq.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
        <behavior >
          <!-- 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" />
    <bindings>
      <wsHttpBinding >
        <binding name="SFG.CRM2011.WebServiceFinHq.BindConfig"    maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
          <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
          <readerQuotas maxDepth="2147483647"
                         maxStringContentLength="2147483647"
                         maxArrayLength="2147483647"
                         maxBytesPerRead="2147483647"
                         maxNameTableCharCount="2147483647" />
        </binding>        
      </wsHttpBinding>
      <mexHttpBinding>
        <binding name="higherMessageSize_MEX"  />                  
      </mexHttpBinding>
        <basicHttpBinding >
        <binding  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
          <readerQuotas maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
   <security>
     <requestFiltering>
       <requestLimits maxAllowedContentLength="9000000" />
     </requestFiltering>
   </security>
 </system.webServer>
</configuration>

下面是我如何调用客户端这个服务...

List<FUMStruct> fList = new List<FUMStruct>();

for (int i = 0; i < 250; i++)
{
    var t = new FUMStruct();
    t.clientID = "1234";
    t.ClientCRMGUID = new Guid("9EACA7AE-FE7E-E211-956A-00505622E202");
    t.CRMAccountCRMGUID = new Guid("A63D9ADC-0CFF-E211-94E9-00505622E202");
    t.Balance = 200 + i;
    fList.Add(t);
}
var serv = new FinHqclientClient();            
serv.UpdateLastFUMGUID(fList.ToArray());
c# wcf http-status-code-400
2个回答
0
投票

我注意到,你已经增加了你的客户的maxRequestLength的,但不是你的服务器:

  <system.web>
    <!-- ... -->
    <httpRuntime  executionTimeout="180" maxRequestLength="2147483647" />
  </system.web>

此配置选项是真的只为服务器相关,因为它设置入站请求的允许大小。在任何情况下,我想这部分添加到您的服务器配置文件,看看是否需要照顾的问题。默认请求大小为4MB,我从经验中知道这可能会导致您报告的错误。


0
投票

这是因为当时在绑定一个“名称”值,。因此没有被应用于我们设置自定义值,并将其载入服务器的默认值(甚至不知道在哪里的“默认”为不同的绑定保持!)我发现了这一点由文章我读了网上,使新使用基本绑定only..which服务未能保持,直到我删除了名字,那么它开始工作!然后,我必须弄清楚如何,因为与绑定做它的wsHttpBinding,如果不指定名称(那么显然你不能引用配置),你会得到各种或安全问题等,并服务无法正常工作..所以解决办法是增加另一个结合没有它的名字属性。

只需要设置在中端服务器端,因为我离开了默认客户端的值(比在上面的例子中的那些更低),它仍然工作。以下是完整web.config..note我怎么过拖欠两个basicHttpBinding的和WsHttpBinding的

<bindings>
      <wsHttpBinding >
        <binding ***name="problemWithValue"***    maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
          <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
          <readerQuotas maxDepth="2147483647"
                         maxStringContentLength="2147483647"
                         maxArrayLength="2147483647"
                         maxBytesPerRead="2147483647"
                         maxNameTableCharCount="2147483647" />
        </binding>
        <binding     maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
          <reliableSession enabled="true" ordered="True" inactivityTimeout="00:10:00" />
          <readerQuotas maxDepth="2147483647"
                         maxStringContentLength="2147483647"
                         maxArrayLength="2147483647"
                         maxBytesPerRead="2147483647"
                         maxNameTableCharCount="2147483647" />
        </binding>
      </wsHttpBinding>
      <mexHttpBinding>
        <binding name="higherMessageSize_MEX"  />                  
      </mexHttpBinding>
        <basicHttpBinding >
        <binding  maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"  >
          <readerQuotas maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
© www.soinside.com 2019 - 2024. All rights reserved.