wcf传输大文件 [英] wcf transfering large files

查看:79
本文介绍了wcf传输大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发wcf应用程序,我想在其中上载和下载本地网络中的大文件.但是我遇到了失败的异常,例如"400错误的请求".

这是服务器端的配置文件,如下所示

I am working on wcf application in which I want upload and download large files in local network. but I got failed exception as "400 bad request".

this is server side config file as below

<configuration>
	<system.servicemodel>
    
    
		<services>
   <service behaviorconfiguration="TransferServiceBehavior" name="WcfTransferTest.transfer">
    <endpoint address="transfer" binding="basicHttpBinding" bindingconfiguration="TransferService">
     contract="WcfTransferTest.Itransfer" />
    <host>
     <baseAddresses>
      <add baseaddress="http://localhost:8001/" />
     </baseAddresses>
    </host>
   </endpoint></service>
  </services>
    
		<bindings>
   <basichttpbinding>
    <binding name="TransferService" maxbuffersize="2147483647" maxreceivedmessagesize="2147483647">
     messageEncoding="Text" transferMode="Streamed">
     <readerquotas maxdepth="2147483647" maxstringcontentlength="2147483647">
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </readerquotas></binding>
   </basichttpbinding>
  </bindings>
    
		<behaviors>
      <servicebehaviors>
        <behavior name="TransferServiceBehavior">
          <servicemetadata httpgetenabled="true" />
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
          <servicedebug includeexceptiondetailinfaults="true" />
          <servicethrottling>
               maxConcurrentCalls="500"
               maxConcurrentSessions="500"
               maxConcurrentInstances="500"/>
        </servicethrottling></behavior>
      </servicebehaviors>
		</behaviors>
    
		<servicehostingenvironment multiplesitebindingsenabled="false" />
	</system.servicemodel>
	<system.webserver>
		<modules runallmanagedmodulesforallrequests="true" />
	</system.webserver>
	<system.web>
		<compilation debug="true" /></system.web></configuration>



这是客户端配置文件,如下所示



this is client side config file as below

<configuration>
    <system.servicemodel>

      <behaviors />

      <bindings>
        <basichttpbinding>
          <binding name="BasicHttpBinding_Itransfer" closetimeout="04:01:00">
            openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
            useDefaultWebProxy="true">
            <readerquotas maxdepth="128" maxstringcontentlength="2147483647">
              maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security mode="None">
              <transport clientcredentialtype="None" proxycredentialtype="None">
                realm="" />
              <message clientcredentialtype="UserName" algorithmsuite="Default" />
            </transport></security>
          </readerquotas></binding>
        </basichttpbinding>
      </bindings>

      <client>
        <endpoint address="http://localhost:3778/transfer.svc/transfer">
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Itransfer"
          contract="FileService.Itransfer" name="BasicHttpBinding_Itransfer" />
      </endpoint></client>
      
    </system.servicemodel>
</configuration>



当我将客户端transferMode设置为缓冲时,它可以上传KB之类的小文件,并且当文件超过1MB时显示错误.但这没有意义,因为我在服务器端将transferMode设置为Streamed,并且客户端应该相同.
当客户端和服务都设置为流时,我收到错误请求400".我花了整整两天的时间,尝试了很多建议,有人说这对他们有用,但是我的建议却没有.

在我的代码块中,大小为65000.

请告诉我具体答案,例如配置文件中的哪个参数有误.
谁能告诉我如何解决此错误?我尝试了许多解决方案,也许我在这里错过了一些东西.
如何解决此问题,以便通过Streaming模式的basicHttpBinding上传大文件?



when I set client side transferMode to buffered it can upload small file like KB, and show error when file more than 1MB . but it does not make sense , because I set transferMode to Streamed on server side, and client should be same.
when client and service both set to streamed , I receive "bad request 400" . it took my two day and I tried many suggestions , people said it works for them , but mine is not.

in my code chunk Size is 65000.

please tell me concrete answer , like which parameter in config file is got wrong.
could anyone tell me how to fix this error? I tried many solution, maybe I am missing something here.
how can fix that in order to upload large file through basicHttpBinding with Streamed mode?

thanks in advance!

推荐答案

这里有一些令人震惊的信息-您实际上可能必须编写一些代码.

在这里查看zuninet的答案:

http://social.msdn.microsoft.com /forums/zh-CN/wcf/thread/f00037f1-02e1-4e1c-b6ed-03fe134f3460/ [
Here''s some shocking info - you may actually have to write some code.

Look at the answer by zuninet here:

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f00037f1-02e1-4e1c-b6ed-03fe134f3460/[^]


我不认为BasicHTTPBinding 足以传输大数据.您需要像此处 [ ^ ]
I don''t think BasicHTTPBinding is enough for transferring large data. You need to go for something like WsHttpMtomBinding as discussed here[^]


这篇关于wcf传输大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆