2013-04-10 45 views
0

我在我的应用程序中使用WCF。来自应用程序I传递一个列表以通过WCF在后端进行处理。如果列表中的no行数很大,那么服务将抛出异常“远程服务器返回意外响应:(400)错误的请求。”WCF抛出异常当传递的列表大小很大

下面

是我的UI web配置

<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配置以及用户界面的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> 
+1

请发表您的** **的服务配置 - 当你传递对象为您服务的错误发生 - 客户端绑定尺寸方面没有任何效果在服务使用的绑定大小上。 – Tim 2013-04-10 18:07:22

+0

我已经更新了我上面的服务配置。 – smv 2013-04-10 20:27:22

回答

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