zoukankan      html  css  js  c++  java
  • 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);
     
     
    
    
             /**********************************/
  • 相关阅读:
    「从零单排canal 03」 canal源码分析大纲
    「从零单排canal 02」canal集群版 + admin控制台 最新搭建姿势(基于1.1.4版本)
    「从零单排canal 01」 canal 10分钟入门(基于1.1.4版本)
    实时数据订阅与分发系统概述
    使用phoenix踩的坑与设计思考
    「从零单排HBase 12」HBase二级索引Phoenix使用与最佳实践
    「从零单排HBase 11」HBase二级索引解决方案
    「从零单排HBase 10」HBase集群多租户实践
    「从零单排HBase 09」HBase的那些数据结构和算法
    Netty源码分析之自定义编解码器
  • 原文地址:https://www.cnblogs.com/LiMin/p/3017312.html
Copyright © 2011-2022 走看看