将大(ish)字节数组传递给 WCF 服务失败,所有最大属性都已达到最大值

jmc*_*ney -1 arrays wcf

我正在调用 WCF 服务中的一个方法,并传递一个包含文件内容的 byte[] 类型属性的 DTO。这工作正常,直到文件达到大约 3 MB,此时它会失败。我能找到的所有信息都讨论了将配置属性设置为更大的值,但我已经把所有内容都最大化了。这是来自我的 web ste 配置文件:

<bindings>
  <wsHttpBinding>
    <binding name="dxWsBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None"  >
        <transport clientCredentialType="None" />
        <message establishSecurityContext="false" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="UserContextClientBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <UserContextBehaviorExtension />
    </behavior>
  </endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

这是来自我的 Web 服务配置文件:

<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
    <behavior name="ErrorLoggerBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <ErrorLogger logName="DXWcfErrorLog" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <wsHttpBinding>
    <binding name="dxWsBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None"  >
        <transport clientCredentialType="None" />
        <message establishSecurityContext="false" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

请注意,我无意在生产中使用这些最大值,但我正在尽一切努力让它发挥作用。

当请求失败时,我在 Web 服务中看不到任何内容。我在两个配置文件中都试过这个:

<system.diagnostics>
  <trace autoflush="true">
    <listeners>
    </listeners>
  </trace>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true">
      <listeners>
        <add name="sdt"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData= "WcfDetailTrace.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

但是当我打开 Web 服务日志文件时,根本没有请求失败的迹象。网站日志文件向我展示了我已经知道的内容。这是我在客户端获得的信息,即网站:

2012-09-25 12:26:46,273 错误发生意外异常
System.ServiceModel.CommunicationException:接收对 http://localhost:52114/DocumentService.svc 的 HTTP 响应时出错。这可能是由于服务端点绑定未使用 HTTP 协议。这也可能是由于服务器中止了 HTTP 请求上下文(可能是由于服务关闭)。有关更多详细信息,请参阅服务器日志。---> System.Net.WebException: 基础连接已关闭:接收时发生意外错误。---> System.IO.IOException: 无法从传输连接读取数据:远程主机强行关闭了现有连接。---> System.Net.Sockets.SocketException: 一个现有的连接被远程主机强行关闭
在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- 内部异常堆栈跟踪结束 ---
在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
在 System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
在 System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- 内部异常堆栈跟踪结束 ---
在 System.Net.HttpWebRequest.GetResponse()
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- 内部异常堆栈跟踪结束 ---

服务器堆栈跟踪:
在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)

在 [0] 处重新抛出异常:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 类型)
在 SI.Doh.Aon.Service.Interface.IServiceBase`1.AddEntity(TDto dto)
在 SI.Doh.Aon.Web.Controllers.DocumentUploaderController.Upload(DocumentEditModel 模型,HttpPostedFileBase FileName) 在 C:\SVN Source\Department_Of_Health\Area_Of_Need\src\SI.Doh.Aon.Web\Controllers\DocumentUploaderController.cs:line 142
在 lambda_method(Closure , ControllerBase , Object[] )
在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数)
在 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 参数)
在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 参数)
在 System.Web.Mvc.ControllerActionInvoker.c__DisplayClass15。
  b__12()
  在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  在 System.Web.Mvc.ControllerActionInvoker.c__DisplayClass15.c__DisplayClass17。
    b__14()
    在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 过滤器, ActionDescriptor actionDescriptor, IDictionary`2 参数)
    在 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
    在 System.Web.Mvc.Controller.ExecuteCore()
    在 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
    在 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
    在 System.Web.Mvc.MvcHandler.c__DisplayClass6.c__DisplayClassb。
      b__5()
      在 System.Web.Mvc.Async.AsyncResultWrapper.c__DisplayClass1。
        b__0()
        在 System.Web.Mvc.Async.AsyncResultWrapper.c__DisplayClass8`1。
          b__7(IAsyncResult _)
          在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
          在 System.Web.Mvc.MvcHandler.c__DisplayClasse。
            b__d()
            在 System.Web.Mvc.SecurityUtil.b__0(动作 f)
   在 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   在 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   在 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult 结果)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously)

Cyb*_*axs 5

httpRuntime 属性中还有一个 maxRequestLength。

<system.web>
    <httpRuntime maxRequestLength="2097151" />
</system.web>
Run Code Online (Sandbox Code Playgroud)