WCF 传输Stream

[ServiceContract]     public interface IService1     {    
 
     [OperationContract]        
 
void UploadFile(FileUploadMessage request);   
 
  }    
 
[MessageContract]    
 
public class FileUploadMessage     {          
 
  // 文件在根目录下的子文件夹名            
 
[MessageHeader(MustUnderstand = true)]        
 
public string SavePath;        
 
   ///文件名           
 
   [MessageHeader(MustUnderstand = true)]      
 
   public string FileName; 
 
   ///文件内容             
 
  [MessageBodyMember(Order = 1)]      
 
   public Stream FileData;       
 
    }
 
 


配置文件::
 
  <system.serviceModel>     <bindings>       <basicHttpBinding>         <binding name="TransferService"            sendTimeout="00:10:00"                  transferMode="Streamed"                  messageEncoding="Text"                  textEncoding="utf-8"                  maxReceivedMessageSize="9223372036854775807">          
 
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"                maxArrayLength="2147483647" maxBytesPerRead="2147483647"                maxNameTableCharCount="2147483647"/>         </binding>       </basicHttpBinding>     </bindings>     <services>       <service behaviorConfiguration="DefaultBehavior" name="WebApplication1.Service1">         <endpoint address="" binding="basicHttpBinding"               bindingConfiguration="TransferService"               contract ="WebApplication1.IService1">         </endpoint>         <host>           <baseAddresses>             <add baseAddress="http://localhost:15246/Service1.svc" />           </baseAddresses>         </host>       </service>     </services>     <behaviors>       <serviceBehaviors>         <behavior name="DefaultBehavior">           <serviceMetadata httpGetEnabled="true" />           <serviceDebug includeExceptionDetailInFaults="true" />           <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>         </behavior>       </serviceBehaviors>     </behaviors>     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />   </system.serviceModel>



上传文件:
 
//A服务器
 
  s1.Service1Client ser1 = new s1.Service1Client();         
                s1.FileUploadMessage f1 = new s1.FileUploadMessage();
                //文件的名称
                f1.FileName = FileUpload1.FileName;
                //路径
                f1.SavePath = "Product";
                //文件
                f1.FileData = FileUpload1.FileContent;
                // //上传文件
                s1.IService1 channel = ser1.ChannelFactory.CreateChannel();
                channel.UploadFile(f1);
 
//b服务器器
 
 s2.Service2Client ser2 = new s2.Service2Client();
            
                s2.FileUploadMessage f2 = new s2.FileUploadMessage();
                //文件的名称
                f2.FileName = FileUpload1.FileName;
                //路径
                f2.SavePath = "Product";
                //文件
                f2.FileData = FileUpload1.FileContent;
                // //上传文件
                s2.IService2 channel2 = ser2.ChannelFactory.CreateChannel();
                channel2.UploadFile(f2);
 
 


         /**********************************/

 

转载于:https://www.cnblogs.com/LiMin/archive/2013/04/12/3017312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值