我在我的应用程序中使用WCF。来自应用程序I将列表传递给后端通过WCF进行处理。如果列表中的no Of行很大,那么该服务将抛出异常“远程服务器返回了意外响应:(400)Bad Request。”
下面是我的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" />
ServiceModel:
<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>
答案 0 :(得分:0)
您似乎没有在服务配置中定义任何端点或绑定,这意味着您将获得默认端点和绑定。由于您的服务使用默认绑定及其默认值,因此无法接收大消息。
您可以通过省略绑定元素中的name
属性来覆盖默认绑定设置。但是,在您的情况下,您在三个已定义的绑定中有不同的设置(至少在安全部分中)。因此,您需要定义绑定并将它们分配给端点。
尝试这样的事情:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" .....>
</basicHttpBinding>
</bindings>
我省略了大部分绑定声明 - 您只需从客户端配置中复制它们即可。
然后在服务中,您在端点元素上为bindingConfig
属性分配特定的绑定配置,如下所示:
<services>
<service .... >
<endpoint address="http://localhost:6789/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</service>
</services>
同样,为简单起见,我省略了大部分配置代码。
这里的关键点是服务需要具有一个绑定,该绑定被配置为接受比默认值更大的消息。增加运行时的maxRequestLength
不会直接影响WCF服务(当然,除非您的请求大于HTTP运行时值)。
您可以在此处详细了解默认端点和绑定 - A Developer's Introduction to Windows Communication Foundation 4