wcf - 当消息大小超过 64K 时,WCF 服务出现 HTTP 400 错误请求错误

标签 wcf http service

我有一个 .NET 4.0 WCF 服务。如果我发送大于 64K 的 soap 消息,则会收到“远程服务器返回意外响应:(400) 错误请求”错误。在我超过 64K 消息大小之前,它一直运行良好。我已经阅读了很多关于如何解决这个错误的帖子,据我所知,我有正确的 web.config 值,但我仍然得到错误。以下是我的 web.config 中的设置。我有什么想念的吗?与我的本地 ASP.NET VS 服务器和远程 Windows 2008 R2 IIS 服务器通信时会发生这种情况。有没有办法实时验证或记录服务绑定(bind)中或调试器中的 maxReceivedMessageSize 设置等?如果有任何不同,该服务将托管在 MVC 中。

<httpRuntime  maxRequestLength="50000000" />

...

...

<bindings>
  <basicHttpBinding>

    <binding name="IpsApiBinding" receiveTimeout="00:15:00" sendTimeout="00:05:00" maxReceivedMessageSize="40000000">
      <readerQuotas maxDepth="5000000" maxStringContentLength="50000000"
        maxArrayLength="50000000" maxBytesPerRead="50000000" />
    </binding>

  </basicHttpBinding>
</bindings>


<services>

  <service behaviorConfiguration="ApiBehavior" name="IPSApi.IpsApi">
    <endpoint behaviorConfiguration="endpointBehavior" binding="basicHttpBinding"
      bindingConfiguration="IpsApiBinding" name="IPSApi.IpsApi"
      contract="IPSApi.IIPSApi" />
  </service>

</services>

<behaviors>

  <endpointBehaviors>
    <behavior name="endpointBehavior">
      <dataContractSerializer maxItemsInObjectGraph="6553600" />
      <callbackDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="ApiBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>

</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"  />

在客户端,堆栈轨迹显示...

Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) ...

最佳答案

我想出了我的问题。这是详细信息。我在 MVC 应用程序中托管我的 WCF 服务。 WCF 服务位于单独的 DLL 中。我在 web.config 中有配置设置,认为它会从那里读取它的配置。来看看,如果在一个单独的DLL中,那么它就不会使用web.config的设置。它只是使用默认绑定(bind)等。

为了让它读取 web.config 中的配置,我使用了 http://blogs.msdn.com/b/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx 中建议的方法.我创建了自己的自定义 ServiceHostFactory 和 ServiceHost。在 ServiceHostFactory.CreateServiceHost 中,我创建了一个 ServiceHost 实例(派生类)。在我的 ServiceHost 派生类中,我接管了 ApplyConfiguration 并从 web.config 加载配置。

有效!

关于wcf - 当消息大小超过 64K 时,WCF 服务出现 HTTP 400 错误请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8611453/

相关文章:

c# - 通过 datacontract 使用 WCF Restful 服务

jquery - WCF:使用 JSONP 将来源列入白名单

java - 在 Android/Java 中使用 JSON/Base64 编码的文件

java - 将 Struts 2.3 迁移到 2.5 时遇到的问题

Android Camera - 从服务在后台运行

java - 前台服务被杀

c# - 将字节数组从 PHP 发布到 .NET WCF 服务

web-services - 使用 Windows 身份验证设置安全 SSL、WCF

java - Java中如何正确读取JSON数据?

linux - 使用 systemctl 或服务命令在 CentOS7 中不会提示用户输入