使用wse(Web Services Enhancements )把伺服器端的檔案傳到用戶端

來源:互聯網
上載者:User
 
比如說,現在網站A有個附件想傳給網站B,我們就可以用WSE來傳。
在伺服器端的webservice檔案service1.asmx中寫入webmethod:
這個是取附件的方法:
[WebMethod]
    public void GetAttachment()
     {
      // 擷取 SoapContext 作為響應訊息
      SoapContext myContext = HttpSoapContext.ResponseContext;
     
     // 字串,表示附件的檔案名稱和路徑。
     string filePath = @"C:My Documents1.txt";
     // 使用檔案名稱來建立新的 DIME 附件,
     // 並通過 MIME 媒體類型
     // 來指定附件編碼。
     DimeAttachment dimeImage = new DimeAttachment(
    "text/xml", TypeFormatEnum.MediaType,
    filePath);
     
     // 指定給 DIME 記錄的 ID 屬性。
     dimeImage.Id = "1.txt";
     // 將新的 DimeAttachment 對象添加到 SoapContext 對象中。
     myContext.Attachments.Add(dimeImage);
     }
在用戶端的web網站下載附件,並寫入到新的檔案中:
private void DownAttachment()
    {
     //Service1WSE : Microsoft.Web.Services.WebServicesClientProtocol      這裡的Service1繼承WSE 中的類
     Service1WSE sw=new Service1WSE(); 
     //從webservice中擷取附件
     sw.GetAttachment();
     //得到附件的流
     Stream str=sw.ResponseSoapContext.Attachments[0].Stream;
     int length=(int)str.Length;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.