(400) 错误请求和更新条目时发生错误

Posted

技术标签:

【中文标题】(400) 错误请求和更新条目时发生错误【英文标题】:(400) Bad Request and An error occurred while updating the entries 【发布时间】:2012-11-09 13:00:50 【问题描述】:

当对象很小的时候我有这个异常

更新条目时出错。详情见内部异常

当对象很大时我有这个异常

远程服务器返回意外响应:(400) Bad Request

客户端:app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService11" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01: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>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:10965/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService11" contract="ServiceReference2.IService1"
                name="BasicHttpBinding_IService11" />
        </client>
    </system.serviceModel>
</configuration>

WCF:web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
      <httpRuntime maxRequestLength="2147483647" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>

  <system.serviceModel>
      <bindings>
          <basicHttpBinding>
              <binding name="customBinding" hostNameComparisonMode="StrongWildcard" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
                     maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Buffered"
                     messageEncoding="Text" textEncoding="utf-8" bypassProxyOnLocal="true" useDefaultWebProxy="true" >
                  <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647"/>
              </binding>
          </basicHttpBinding>
      </bindings>
    <behaviors>
      <serviceBehaviors>
        <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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings><add name="SASPEEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=SASPE;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="SASPEEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=SASPE;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /><add name="SASPEEntities2" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=SASPE;integrated security=True;pooling=False;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>


</configuration>

和 wcf:web.debug.config

<?xml version="1.0"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <system.serviceModel>
        <services>
            <service name="WcfService1.Service1">
                <endpoint address="http://localhost:10965/Service1.svc?wsdl"
                    binding="basicHttpBinding"  bindingConfiguration="customBinding" contract="WcfService1.IService1"  />
            </service>
        </services>
    </system.serviceModel>
</configuration>

【问题讨论】:

这似乎更像是您的请求和处理逻辑中的一些错误。 【参考方案1】:

错误“更新条目时发生错误。有关详细信息,请参阅内部异常”当我遇到实体框架与数据库通信的问题(列不匹配或溢出等...)时,我经常看到如果您执行您的 WCF 公开类在不通过 WCF 的情况下调用的代码,您应该能够查看内部异常并找出 EF 不喜欢您的数据库的哪些地方。

传递大数据时的 400 bad request 看起来很像这里描述的问题-Large WCF web service request failing with (400) HTTP Bad Request

【讨论】:

以上是关于(400) 错误请求和更新条目时发生错误的主要内容,如果未能解决你的问题,请参考以下文章

打开网站时出现HTTP 400 错误的请求,这是啥意思,要怎么解决?

get请求400错误,post请求405错误

Web api: 400 错误请求

错误请求 - 请求太长HTTP错误400.请求标头的大小太长

尝试将项目添加到数据库时出现更新条目错误

更新条目时出错