.net - WCF 错误 MTOM 编码 + 从客户端向服务发送大数据

标签 .net wcf mtom

我正在尝试this example来自 MSDN。

我尝试使用 FileStream 和 WCF 发送文件。

当我发送只有几个字节的小文件时,我会得到输出。但是,当我尝试发送几 MB 的文件时,出现错误:

System.ServiceModel.CommunicationException: An error (The request was aborted: The request was cancelled).

我已经更改了绑定(bind)内的最大值并将其设置为更大的值。我还更改了超时。我启用了跟踪,但跟踪中没有发现错误。

我无法弄清楚这个问题。有人可以帮忙吗?

这是服务..配置文件

<behaviors>
  <serviceBehaviors>
    <behavior name="wsHttpServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <wsHttpBinding>
    <binding name="customWsHttpBinding" messageEncoding="Mtom"
             openTimeout="00:10:00"  maxReceivedMessageSize="2147483647"
             closeTimeout="00:10:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:10:00">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxNameTableCharCount="16384"/>
    </binding>       
  </wsHttpBinding>
</bindings>

<services>
  <service name="MTOMUploadService.UploadService" behaviorConfiguration="wsHttpServiceBehavior">
    <endpoint address="mex" contract="IMetadataExchange" binding="wsHttpBinding"/>
    <endpoint contract="MTOMUploadService.IUploadService" binding="wsHttpBinding"  bindingConfiguration="customWsHttpBinding" />
  </service>
</services>

这是客户端配置......

<system.serviceModel>

    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IUploadService" closeTimeout="00:10:00"
                openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://machinename:4575/MTOMUploadService.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IUploadService"
            contract="IUploadService" name="WSHttpBinding_IUploadService">
            <identity>
                <servicePrincipalName value="machinename" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

最佳答案

只需将其放入您的 wcf web.config 中即可:

<system.web>
  <httpRuntime maxRequestLength="2097151" />
</system.web>

关于.net - WCF 错误 MTOM 编码 + 从客户端向服务发送大数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12332708/

相关文章:

EndpointDispatcher 处的 WCF 和 ContractFilter 不匹配

c# - 使用 c# 代码在 Header 中使用 Assertion Saml2 创建 SOAP 消息

c# - 如何在不读取结束的情况下中止来自 WCF 服务的流?

spring - java.lang.NoSuchFieldError : REFLECTION

.net - 绕过 Windows Server 2008 中的 session 0 隔离 - 成功,但仍然不可见

.net - 具有预编译 View 的助手

.net - Azure 云存储 SDK UploadFromStreamAsync 存储 0 字节

c# - IIS 7 ERR_CONNECTION_TIMED_OUT 仅适用于公共(public) IP

java - 使用 JAX-WS 构建大型 MTOM/XOP 消息

c# - 自定义 BotState 存储 - 删除旧的状态数据条目