自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WCF Stream實際應(yīng)用功能體驗

開發(fā) 開發(fā)工具
我們今天將會通過這篇文章為大家詳細講解一下有關(guān)WCF Stream在實現(xiàn)大文件上傳方面的相關(guān)操作步驟,讓大家充分掌握這方面的應(yīng)用技術(shù)。

WCF中的Stream操作有很多使用方法,其中有一種比較常用的就是我們今天為大家介紹的關(guān)于實現(xiàn)上傳大文件的操作方法。在這里我們就會通過這篇文章為大家詳細介紹一下相關(guān)的操作方法。

WCF Stream操作步驟之Test.ASPX.C

  1. protected void Button3_Click(object sender, EventArgs e)  
  2. {  
  3. FileData file = new FileData();  
  4. file.filename = FileUpload1.FileName;  
  5. file.data = new FileStream(FileUpload1.PostedFile.
    FileName, FileMode.Open);  
  6. GetDataServiceClient c = new GetDataServiceClient();  
  7. c.UploadFile(file.filename, file.data);  
  8. Response.Write("文件傳輸成功!");  
  9. c.Close();  

WCF Stream操作步驟之Contract

  1. [ServiceContract]  
  2. public interface IGetDataService  
  3. {  
  4. [OperationContract]  
  5. void UploadFile(FileData file);  
  6. }  
  7. [MessageContract]  
  8. public class FileData  
  9. {  
  10. [MessageHeader]  
  11. public string filename;  
  12. [MessageBodyMember]  
  13. public Stream data;  

WCF Stream操作步驟之ServiceLib

  1. public class GetDataService : IGetDataService  
  2. {  
  3. public void UploadFile(FileData file)  
  4. {  
  5. FileStream fs = new FileStream("Files\\"+file.filename, 
    FileMode.OpenOrCreate);  
  6. try  
  7. {  
  8. BinaryReader reader = new BinaryReader(file.data);  
  9. byte[] buffer;  
  10. BinaryWriter writer = new BinaryWriter(fs);  
  11. long offset = fs.Length;  
  12. writer.Seek((int)offset, SeekOrigin.Begin);  
  13. do  
  14. {  
  15. buffer = reader.ReadBytes(1024);  
  16. writer.Write(buffer);  
  17. } while (buffer.Length > 0);  
  18. }  
  19. catch(Exception e)  
  20. {  
  21. }  
  22. finally  
  23. {  
  24. fs.Close();  
  25. file.data.Close();  
  26. }  
  27. }  

WCF Stream操作步驟之App.config

  1. < ?xml version="1.0" encoding="utf-8" ?> 
  2. < configuration> 
  3. < system.serviceModel> 
  4. < services> 
  5. < !--name - 提供服務(wù)的類名--> 
  6. < !--behaviorConfiguration - 指定相關(guān)的行為配置--> 
  7. < service name="ServiceLib.GetDataService" 
    behaviorConfiguration="BindingBehavior"> 
  8. < !--address - 服務(wù)地址--> 
  9. < !--binding - 通信方式--> 
  10. < !--contract - 服務(wù)契約--> 
  11. < !--< endpoint binding="basicHttpBinding" contract=
    "WCF.ServiceLib.Binding.IHello" address="Hello" />--> 
  12. < !--元數(shù)據(jù)交換的endpoint--> 
  13. < !--注:address是mex,它會和host/baseAddresses節(jié)點中的baseAddress做拼接,
    即提供元數(shù)據(jù)交換的地址為:http://localhost:12345/Binding/mex--
    > 
  14. < endpoint binding="basicHttpBinding" bindingConfiguration =
    "DocumentExplorerServiceBinding" contract="Contract.IGetDataService" 
    address="mex" /> 
  15. < host> 
  16. < baseAddresses> 
  17. < add baseAddress="http://localhost:8008/"/> 
  18. < /baseAddresses> 
  19. < /host> 
  20. < /service> 
  21. < /services> 
  22. < behaviors> 
  23. < serviceBehaviors> 
  24. < behavior name="BindingBehavior"> 
  25. < !--httpGetEnabled - 使用get方式提供服務(wù)--> 
  26. < serviceMetadata httpGetEnabled="true" /> 
  27. < /behavior> 
  28. < /serviceBehaviors> 
  29. < /behaviors> 
  30. < bindings> 
  31. < basicHttpBinding> 
  32. < binding name="DocumentExplorerServiceBinding" 
  33. sendTimeout="00:10:00" 
  34. transferMode="Streamed" 
  35. maxReceivedMessageSize="9223372036854775807"> 
  36. < /binding> 
  37. < /basicHttpBinding> 
  38. < /bindings> 
  39. < /system.serviceModel> 
  40. < /configuration> 

WCF Stream操作步驟之web.config

  1. < system.serviceModel> 
  2. < bindings> 
  3. < basicHttpBinding> 
  4. < binding name="BasicHttpBinding_IGetDataService" closeTimeout="00:01:00" 
  5. openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
  6. allowCookies="false" bypassProxyOnLocal="false" 
    hostNameComparisonMode="StrongWildcard" 
  7. maxBufferSize="65536" maxBufferPoolSize="524288" 
    maxReceivedMessageSize="65536" 
  8. transferMode="Streamed" 
  9. useDefaultWebProxy="true"> 
  10. < readerQuotas maxDepth="32" maxStringContentLength="8192" 
    maxArrayLength="16384" 
  11. maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
  12. < security mode="None"> 
  13. < transport clientCredentialType="None" proxyCredentialType="None" 
  14. realm="" /> 
  15. < message clientCredentialType="UserName" algorithmSuite="Default" /> 
  16. < /security> 
  17. < /binding> 
  18. < /basicHttpBinding> 
  19. < /bindings> 
  20. < client> 
  21. < endpoint address="http://192.168.0.19:8008/mex" 
    binding="basicHttpBinding" 
  22. bindingConfiguration="BasicHttpBinding_IGetDataService" 
    contract="IGetDataService" 
  23. name="BasicHttpBinding_IGetDataService" /> 
  24. < /client> 
  25. < /system.serviceModel> 

以上就是我們?yōu)榇蠹以敿毥榻B的有關(guān)WCF Stream的操作方法。

【編輯推薦】

  1. WCF行為擴展正確內(nèi)容應(yīng)用技巧分享
  2. ASP.NET Ajax調(diào)用WCF服務(wù)正確實現(xiàn)方法淺談
  3. WCF全局錯誤捕獲正確內(nèi)容解析
  4. WCF傳輸安全機制相關(guān)內(nèi)容詳解
  5. WCF創(chuàng)建WebService正確操作步驟詳解
責(zé)任編輯:曹凱 來源: CSDN
相關(guān)推薦

2010-02-25 16:12:23

WCF IDispos

2010-05-31 15:49:29

MySQL臨時表

2010-03-01 13:06:49

WCF繼承

2010-02-22 10:42:12

WCF Stream

2009-12-21 14:49:27

2010-03-02 17:35:20

WCF服務(wù)加載

2010-02-22 13:28:05

WCF異步調(diào)用

2010-02-23 10:25:29

2010-02-24 14:05:08

WCF openati

2013-09-02 16:04:20

Windows

2010-03-01 10:45:59

WCF集合類

2010-03-01 17:52:03

WCF選擇綁定

2009-12-21 14:58:57

WCF用戶密碼認證

2010-01-26 10:38:56

Android消息傳遞

2010-02-25 17:22:39

WCF服務(wù)行為

2017-11-07 22:19:55

iOS 蘋果App

2020-12-18 13:00:31

Xedit文本編輯器Linux

2009-11-05 15:00:26

WCF Stream

2010-03-01 15:51:01

WCF限流

2009-11-06 16:35:56

WCF Stream對
點贊
收藏

51CTO技術(shù)棧公眾號