【问题标题】:WCF not allowing large list . Throwing "The remote server returned an unexpected response: (400) Bad Request." exceptionWCF 不允许大列表。抛出“远程服务器返回意外响应:(400) 错误请求。”例外
【发布时间】:2013-04-17 11:47:42
【问题描述】:

我有一个包含 9 个字段的列表。当我通过一个较小的列表(比如 50 行)时,应用程序运行良好。如果我传递更大的列表,我的服务将抛出异常“远程服务器返回意外响应:(400) 错误请求。”例外。请帮我解决这个问题。

我的网络配置如下

 <?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>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />

  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Windows">
            <!--<forms loginUrl="~/Account/Login.aspx" timeout="2880" />-->
    </authentication>
    <identity impersonate="false" />
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

    <httpRuntime maxRequestLength="2147483647" executionTimeout="3600"/>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors >
        <behavior name="Behavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" closeTimeout="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" 
          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="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8"
          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="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" 
          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" />          
    </client>
  </system.serviceModel>
</configuration>

我的 wcf 配置如下

  <?xml version="1.0"?>
    <configuration>
      <connectionStrings>

        <add name="DEFAULT"  connectionString="server=DEV1;Port=52;database=UTIL;User=ara;password=me;Charset=iso_1;Connect Timeout=100" />

      </connectionStrings>
      <appSettings>
        <add key="DEFAULT_SERVER" value="UAT"/>
        <add key="DEFAULT_DATABASE" value="UTIL"/>
        <add key="DEFAULT_PORT" value="480"/>
        <add key="DEFAULT_USER" value="fator"/>
        <add key ="DEFAULT_PASSWORD" value="U212ajUyODY="/>
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />

          <httpRuntime maxRequestLength="2147483647" executionTimeout="3600"/>

      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="Behavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- 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>

        <services>

        </services>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>

    </configuration>

我使用端点和绑定修改了我的服务 Web 配置,如下所示。但我仍然遇到同样的错误

<?xml version="1.0"?>
<configuration>
  <connectionStrings>

    <add name="DEFAULT"  connectionString="server=DEV;Port=52;database=UTIL;User=ar;password=me3;Charset=iso_1;Connect Timeout=100" />

  </connectionStrings>
  <appSettings>
    <add key="DEFAULT_SERVER" value="UA"/>
    <add key="DEFAULT_DATABASE" value="UTIL"/>
    <add key="DEFAULT_PORT" value="45"/>
    <add key="DEFAULT_USER" value="fr"/>
    <add key ="DEFAULT_PASSWORD" value="Y="/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />

      <httpRuntime maxRequestLength="2147483647" executionTimeout="3600"/>

  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 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"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service name="Service.Service1" behaviorConfiguration="Behavior">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_IService1"
                  contract="Service.IService1"
                  name="BasicHttpBinding_IService1" />
        <endpoint address="mex" 
                  binding="mexHttpBinding"
                  contract="IMetaDataExchange"></endpoint>
        <host>
          <timeouts openTimeout="00:30:00" />
        </host>
      </service>
      <service name="Service.ErrorService" behaviorConfiguration="Behavior">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_IErrorService"
                  contract="Service.IErrorService"
                  name="BasicHttpBinding_IErrorService" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetaDataExchange"></endpoint>
        <host>
          <timeouts openTimeout="00:30:00" />
        </host>
      </service>
      <service name="Service.SecurityUserService" behaviorConfiguration="Behavior">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_ISecurityUserService"
                  contract="Service.ISecurityUserService"
                  name="BasicHttpBinding_IErrorService" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetaDataExchange"></endpoint>
        <host>
          <timeouts openTimeout="00:30:00" />
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
      <binding name="BasicHttpBinding_IService1" closeTimeout="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" 
        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="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8"
          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="00:20:00"
        openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" 
          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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

我猜我明确定义的端点和绑定没有被服务使用。如果我配置了服务错误,请纠正我

【问题讨论】:

    标签: c# asp.net wcf silverlight


    【解决方案1】:

    试试下面的标签

    您的应用程序中的问题是您使用不同的合同名称进行服务。 在 Web.Config 中,您将合同名称用作 Service1 的“ServiceReference1.IService1”,而在服务 Web 配置中,您将合同名称用作“Service.IService1”。也许它会解决你的问题。

    <system.serviceModel>
        <diagnostics performanceCounters ="All"/>  
        <services>
          <service behaviorConfiguration ="Default" name ="Service.IService1">
            <endpoint address="" behaviorConfiguration="Web" binding ="basicHttpBinding" contract ="ServiceReference1.IService1"></endpoint>
            <host>
              <baseAddresses>                
              </baseAddresses>
            </host>
          </service>      
        </services>
        <behaviors>      
          <serviceBehaviors>
            <behavior name ="Default">
    
              <serviceThrottling maxConcurrentCalls ="100" maxConcurrentSessions ="100"/>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true" />
              <!-- 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="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name ="Web"></behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment  multipleSiteBindingsEnabled="true" />
    
      </system.serviceModel>
    

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多