";远程服务器返回了一个意外的响应:(400)错误请求;
本文关键字:一个 意外 请求 错误 响应 quot 服务器 返回 | 更新日期: 2023-09-27 18:28:48
我现在完全被这个问题难住了。在过去的两天里,我一直在阅读各种文章和博客,并做出了大部分建议的更改,但我仍然有这个问题。
基本上,我将一个数组对象作为参数从客户端传递给服务,然后会出现上面的错误。
我可以处理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());
这是因为绑定中有一个"name"值,。因此,我们设置的自定义值没有被应用,它正在加载服务器默认值(甚至不确定不同绑定的"默认值"保存在哪里!)我在网上读到的一篇文章中发现了这一点,该文章只使用基本绑定创建了一个新服务。。它一直失败,直到我删除了这个名字,它才开始工作!然后我不得不想办法为wsHttpBinding做这件事,因为有了这个绑定,如果你不指定名称(然后显然你不能引用配置),你会遇到各种各样的安全问题等,服务就不起作用了。。所以解决方案是添加另一个没有name属性的绑定。
这些设置最终只在服务器端需要,因为我保留了默认的客户端值(低于上面示例中的值),它仍然有效。下面是完整的web.config..注意我是如何默认使用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>
我注意到您增加了客户端的maxRequestLength,但没有增加服务器的maxRequestLength:
<system.web>
<!-- ... -->
<httpRuntime executionTimeout="180" maxRequestLength="2147483647" />
</system.web>
这个配置选项实际上只与服务器相关,因为它设置了入站请求的允许大小。在任何情况下,我都会将这一部分添加到服务器配置文件中,看看这是否解决了问题。默认的请求大小是4MB,我从经验中知道这可能会导致您报告的错误。