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

时间:2012-09-08 16:57:51

标签: .net wcf mtom

我正在尝试从MSDN发送this example

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

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

  

System.ServiceModel.CommunicationException:错误(请求已中止:请求已取消)。

我更改了绑定中的最大值并将其设置为更大的值。我也改变了超时。我已启用跟踪,但跟踪中没有找到错误。

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

这是服务..配置文件

<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>

1 个答案:

答案 0 :(得分:2)

将它放入你的wcf web.config:

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