首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于WCF下传上载文件的有关问题

2012-09-18 
关于WCF上传下载文件的问题我最近在做一个基于WCF的网络文件系统,在使用WCF上传下载文件有下面的一些问题:

关于WCF上传下载文件的问题
我最近在做一个基于WCF的网络文件系统,在使用WCF上传下载文件有下面的一些问题:
访问采用wsHttpBinding绑定,可是不支持流,于是单独定义了一个basicHttpBinding的终结点,参考MSDN中流的例程,可以上传文件,包括2G以上的文件都可以,可是basicHttpBinding不支持会话,而且流模式的接口中只能有一个流参数,服务器如何知道客户端的文件相关信息,如文件名等内容信息?
于是我将流传输文件的方式改成了netTcpBinding绑定,因为netTcpBinding支持会话,可运行时出错,一查,原因在于在WCF中流和会话不可同时支持,netTcpBinding采用流和Buffered模式倒是可以。
如何使用WCF来进行文件上传下载呢?

[解决办法]
netTcpBinding肯定不会出错,我自己写过的。另外所谓的是否支持会话和获取文件信息有何关系?当一个文件要上传时,请求对应的函数参数中给一个文件名即可,非常简单的事。
[解决办法]
传文件建议用 stream
服务端配置

XML code
<bindings>            <netTcpBinding>        <binding name="customTcpBinding"   transferMode="Streamed"   maxReceivedMessageSize="904800000" receiveTimeout="01:30:00" >          <!--缺省 -->          <security mode="TransportWithMessageCredential">            <message clientCredentialType="UserName"/>          </security>        </binding>            </netTcpBinding>        </bindings>        <behaviors>      <serviceBehaviors>    <behavior name="FileServer.ServicesBehavior">     <serviceMetadata httpsGetEnabled="false" />      <serviceDebug includeExceptionDetailInFaults="false" />      <serviceCredentials>        <issuedTokenAuthentication allowUntrustedRsaIssuers="true"></issuedTokenAuthentication>        <clientCertificate>          <authentication certificateValidationMode="None"/>        </clientCertificate>        <serviceCertificate findValue="MyServer" storeLocation="CurrentUser" x509FindType="FindBySubjectName" storeName="My"/>        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="FileServer.MyCustomValidator,FileServer"/>      </serviceCredentials>    </behavior>
[解决办法]
说道流传输,默认的流传输是不支持断点续传的,我重写了文件流,让流传输支持断点续传。代码不难,有需要的吗?

热点排行