2

我正在从 MSDN尝试这个示例。

我尝试使用 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>
4

1 回答 1

2

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

<system.web>
  <httpRuntime maxRequestLength="2097151" />
</system.web>
于 2013-09-06T12:12:56.793 回答