0

我读了这篇文章http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP通过 WCF 上传大文件。

我创建了相同的配置,但即使我添加了属性,我也只是上传了 48kb 文件maxReceivedMessageSize ="2147483647"。当我尝试上传超过 48kb 的文件时出现错误

远程服务器返回错误:(413)请求实体太大。

我错了还是错过了什么?下面是我的配置

服务器配置:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="4800" maxRequestLength="2097150"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <!--BINDING-->
    <bindings>
      <basicHttpBinding>
        <binding name="TransferService" 
                 closeTimeout="00:10:00"
                 maxBufferPoolSize="2147483647"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize ="2147483647" 
                 openTimeout="00:10:00" 
                 receiveTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 messageEncoding="Text"
                 transferMode="Streamed"
                 >
          <readerQuotas
            maxDepth="2147483647" 
            maxStringContentLength="2147483647"
            maxBytesPerRead="2147483647" 
            maxNameTableCharCount="2147483647" 
            maxArrayLength="2147483647"/>
        </binding>
        </basicHttpBinding>
    </bindings>

    <!--SERVICE-->
    <services>
      <service name="TransferService.TransferService" 
               behaviorConfiguration="TransferServiceBehavior" >
         <endpoint  
             address="" 
             binding="basicHttpBinding" 
             bindingConfiguration="TransferService" 
             contract="TransferService.ITransferService" >
        </endpoint>
      </service>
    </services>

    <!--BEHAVIOR-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="TransferServiceBehavior">
          <serviceMetadata httpGetEnabled="true"  />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
 <system.webServer>
   <security>
     <requestFiltering>
       <requestLimits maxAllowedContentLength="500000000"></requestLimits>
     </requestFiltering>
   </security>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

网络客户端配置:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ITransferService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint name="BasicHttpBinding_ITransferService" 
          address="http://localhost/transfer/TransferService.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ITransferService"
          contract="TransferService.ITransferService" />
    </client>
  </system.serviceModel>

请提出任何解决方案。

提前致谢


现在我已经按照您的建议更改了配置,但它仍然引发相同的错误 400 或 413。下面是我的测试项目。我不知道为什么?(环境:Window 7 Pro 64 位,IIS7,WCF 4.0)

https://skydrive.live.com/redir?resid=BFE92959302FBAA0!105&authkey=!ANO_URChpql9gKE

我花了两个星期来研究,但这是同样的错误。

请帮我。提前致谢。

4

3 回答 3

2

好吧,客户端配置还必须定义相同的绑定配置(具有更大的传输大小),并在其端点配置中指定该绑定配置!

因此,将您的客户端配置更改为:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
        <binding name="TransferService" 
                 closeTimeout="00:10:00"
                 maxBufferPoolSize="2147483647"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize ="2147483647" 
                 openTimeout="00:10:00" 
                 receiveTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 messageEncoding="Text"
                 transferMode="Streamed"
                 >
          <readerQuotas
            maxDepth="2147483647" 
            maxStringContentLength="2147483647"
            maxBytesPerRead="2147483647" 
            maxNameTableCharCount="2147483647" 
            maxArrayLength="2147483647"/>
        </binding>
        </basicHttpBinding>
    </bindings>

    <client>
      <endpoint name="BasicHttpBinding_ITransferService" 
          address="http://localhost/transfer/TransferService.svc"
          binding="basicHttpBinding" 
          bindingConfiguration="TransferService"
          contract="TransferService.ITransferService" />
    </client>
  </system.serviceModel>

然后您应该在客户端和服务器上具有相同的设置,然后这些设置将变得有用!

于 2012-11-02T09:27:43.277 回答
1

我检查了你的项目,用这个替换你的 webconfig 并更新服务参考再试一次,

  <?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="4800" maxRequestLength="2097150"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <!--BINDDING-->
    <bindings>
      <basicHttpBinding>
      </basicHttpBinding>
      <customBinding>
        <binding name="LargeSilverlight" closeTimeout="00:21:00" openTimeout="00:20:00"
          receiveTimeout="00:20:00" sendTimeout="00:50:00">
          <textMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
              maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
    </client>
    <!--SERVICE-->
    <services>
      <service name="TransferService.TransferService"  behaviorConfiguration="SilverlightWCFLargeDataApplication" >
        <endpoint  address="" binding="customBinding" bindingConfiguration="LargeSilverlight" behaviorConfiguration="SilverlightWCFLargeDataApplication" contract="TransferService.ITransferService" >
        </endpoint>

      </service>
    </services>

    <!--BEHAVIOR-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>

      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>


  </system.serviceModel>
  <system.webServer>

    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="500000000"></requestLimits>
      </requestFiltering>
    </security>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>
于 2012-11-05T04:54:45.853 回答
0

我面临同样的问题。我在配置文件中使用了这个代码然后我可以上传 25MB 文件试试这个

<system.serviceModel>
      <bindings>
           <basicHttpBinding>
               <binding name="webserviceMOSSuiteSoap" 
              closeTimeout="00:01:00" 
              maxBufferPoolSize="20000000" 
              maxBufferSize="20000000" 
              maxReceivedMessageSize="20000000" 
              openTimeout="00:01:00" 
              receiveTimeout="00:10:00" 
              sendTimeout="00:01:00" 
              messageEncoding="Text" 
              transferMode="Buffered" 
              allowCookies="false" 
              bypassProxyOnLocal="false" 
              hostNameComparisonMode="StrongWildcard"                        
              textEncoding="utf-8"                       
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" 
                            maxStringContentLength="20000000" 
                            maxArrayLength="20000000" 
                            maxBytesPerRead="20000000" 
                            maxNameTableCharCount="20000000"/>
              <security mode="None">
              <transport clientCredentialType="None" 
                    proxyCredentialType="None" 
                    realm=""/>
            <message clientCredentialType="UserName" 
                 algorithmSuite="Default"/>
                          </security> 
                    </binding>
            </basicHttpBinding>   
      </bindings>
<client>      
        <endpoint address="http://localhost/WebServiceConnect/webservice.asmx" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="webserviceMOSSuiteSoap" 
                  contract="ServiceReference1.webserviceMOSSuiteSoap" 
                  name="webserviceMOSSuiteSoap"/>
    </client>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                               multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
于 2012-11-03T02:01:04.707 回答