当transferMode =“Streamed”时,使用WCF服务的文件上传不起作用

时间:2009-10-07 14:41:29

标签: wcf

配置详情如下:

托管的Wcf服务的Web.config。

<basicHttpBinding>
    <binding name="HttpBinding_MTOM" messageEncoding="Mtom" 
             transferMode="Streamed" maxBufferSize="65536" 
             maxReceivedMessageSize="534773760">
      <security mode="None">
        <transport clientCredentialType="None" />
      </security>
    </binding>
</basicHttpBinding>
<services>
   <service name="OA.Smart.Services.FileTransferService"
            behaviorConfiguration="FileTransferServiceBehavior">
      <endpoint address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="HttpBinding_MTOM"
                contract="OA.Smart.ServiceContract.IFileTransferService">
         <identity>
            <dns value="localhost" />
         </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>      
</services>
<behavior name="FileTransferServiceBehavior">
   <serviceMetadata httpGetEnabled="true" />
   <serviceDebug includeExceptionDetailInFaults="false" />
</behavior>

我有一个访问此WCF服务的智能客户端应用程序.App.Config如下

<bindings>
  <basicHttpBinding>
 <binding name="BasicHttpBinding_IFileTransferService" 
              closeTimeout="00:30:00" openTimeout="00:30: 
              receiveTimeout="00:30:00" sendTimeout="00:30:00"
      allowCookies="false" bypassProxyOnLocal="false" 
              hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" 
              maxReceivedMessageSize="65536"
      messageEncoding="Mtom" textEncoding="utf-8" 
              transferMode="Streamed" useDefaultWebProxy="true">
     <readerQuotas 
              maxDepth="32" maxStringContentLength="8192" 
              maxArrayLength="16384" maxBytesPerRead="4096" 
              maxNameTableCharCount="16384" />
         <security mode="None">
             <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
             <message clientCredentialType="UserName" algorithmSuite="Default" />
         </security>
      </binding>
   </basicHttpBinding>
</bindings>
<client>
    <endpoint 
       address="http://localhost:4149/OA.Smart.ServiceHost/FileTransferService.svc"
       behaviorConfiguration="defaultServiceBehaviour"
       binding="basicHttpBinding"  
       bindingConfiguration="BasicHttpBinding_IFileTransferService"
       contract="FileTransferServiceReference.IFileTransferService"
       name="BasicHttpBinding_IFileTransferService">
    </endpoint>
</client>
<behaviors>
   <endpointBehaviors>
       <behavior name="defaultServiceBehaviour">
           <dataContractSerializer maxItemsInObjectGraph="2147483646" />
       </behavior>
   </endpointBehaviors>
</behaviors>

每当我尝试上传文件时都会使用此配置,它会抛出错误

System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse() 
   at System.ServiceModel.Channels.HttpChannelFactory.
        HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)}

但是,如果我将transferMode =“Streamed”更改为“Buffered”,它将按预期工作。我不明白为什么它会这样。 WCF服务的TransferMode是流式传输的,因此它应该与流式传输一起使用。

请告诉我如何使用transferMode =“Streamed”

2 个答案:

答案 0 :(得分:2)

问题在于托管WCF服务。我曾在Cassini(与VS2008一起提供的Web服务器)而不是IIS上托管它们.Cassini不允许通过HTTP进行流式传输。所以只使用IIS来托管WCF服务解决了这个问题。

答案 1 :(得分:0)

您只想将文件上传到服务器?在这种情况下,您是否尝试过使用

transferMode="StreamedRequest"

而不是“流”?有什么不同吗?

另外,你能告诉我们服务合同(你正在编程的界面)吗?这也可能给我们一个线索。

马克