我在我的应用程序中使用 WCF。从应用程序我通过 WCF 传递一个列表以在后端处理。如果列表中的行数很大,则服务会抛出异常“远程服务器返回意外响应:(400) 错误请求。”
下面是我的 UI 网络配置
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_IErrorService" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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>
<binding name="BasicHttpBinding_IService11" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_ISecurityUserService" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:6789/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
<endpoint address="http://localhost:6789/ErrorService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IErrorService" contract="ErrorServiceReference.IErrorService"
name="BasicHttpBinding_IErrorService" />
<endpoint address="http://localhost:6789/SecurityUserService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISecurityUserService"
contract="SecurityUserServiceReference.ISecurityUserService"
name="BasicHttpBinding_ISecurityUserService" />
<endpoint address="http://localhost:6789/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService11" contract="ServiceReference.IService1"
name="BasicHttpBinding_IService11" />
</client>
</system.serviceModel>
还将以下标记添加到 WCF Web 配置以及 UI Web 配置
<system.web>
<httpRuntime maxRequestLength="512000" />
</system.web>
我的服务配置如下
<httpRuntime maxRequestLength="512000" />
服务模式:
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<modules runAllManagedModulesForAllRequests="true"/>
我修改了服务 Web 配置 。我仍然遇到同样的问题。请帮助我
<services>
<service name="BasicHttpBinding_IService1" behaviorConfiguration="Behavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1"/>
</service>
<service name="BasicHttpBinding_IErrorService" behaviorConfiguration="Behavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IErrorService"
contract="ErrorServiceReference.IErrorService"/>
</service>
<service name="BasicHttpBinding_ISecurityUserService" behaviorConfiguration="Behavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISecurityUserService"
contract="SecurityUserServiceReference.ISecurityUserService"/>
</service>
</services>
and bindings
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_IErrorService" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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>
<binding name="BasicHttpBinding_ISecurityUserService" closeTimeout="10:20:00"
openTimeout="10:20:00" receiveTimeout="10:20:00" sendTimeout="10:20: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="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>