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

时间:2012-11-21 09:52:57

标签: c# .net wcf entity-framework

当对象很小时我有这个例外

  

更新条目时发生错误。有关详细信息,请参阅内部异常

当对象很大时我有这个例外

  

远程服务器返回意外响应:(400)错误请求

客户端: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 个答案:

答案 0 :(得分:0)

错误“更新条目时发生错误。有关详细信息,请参阅内部异常”我经常看到实体框架与数据库通信时出现问题(列不匹配或溢出等等)如果执行你的WCF暴露的类正在通过WCF调用的代码,你应该能够查看内部异常并找出EF对你的数据库不喜欢的内容。

传递大数据时的400错误请求看起来很像这里描述的问题 -

Large WCF web service request failing with (400) HTTP Bad Request