WCF不允许大列表.远程服务器返回了一个意外的响应:(400)错误的请求."例外

本文关键字:响应 不允许 错误 请求 例外 quot 意外 一个 返回 服务器 WCF | 更新日期: 2023-09-27 18:09:42

我有一个有9个字段的列表。当我通过一个较小的列表(说50行),应用程序工作正常。如果我传递一个更大的列表,我的服务抛出异常"远程服务器返回了一个意外的响应:(400)错误的请求。"异常。请帮我解决这个问题。

我的Web配置如下

 <?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>

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

WCF不允许大列表.远程服务器返回了一个意外的响应:(400)错误的请求."例外

试试下面的标签

您的应用程序中的问题是您为服务使用了不同的契约名称。在网络上。配置您使用的合同名称为"ServiceReference1"。在service 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>