Use wse (Web Services Enhancements) to upload files from the server to the client

Source: Internet
Author: User
Tags web services
For example, if site A has an attachment that we want to transmit to site B, we can use WSE to transmit it.
Write the webmethod to the webservice file service1.asmx on the server:
This is the method for obtaining the attachment:
Public void GetAttachment ()
// Get SoapContext as response message
SoapContext myContext = HttpSoapContext. ResponseContext;
// String, indicating the file name and path of the attachment.
String filePath = @ "C: My Documents1.txt ";
// Use the file name to create a new DIME attachment,
// And use the MIME media type
// Specify the attachment encoding.
DimeAttachment dimeImage = new DimeAttachment (
"Text/xml", TypeFormatEnum. MediaType,
FilePath );
// ID attribute specified for the DIME record.
DimeImage. Id = "1.txt ";
// Add the new DimeAttachment object to the SoapContext object.
MyContext. Attachments. Add (dimeImage );
Download the attachment from the client's web site and write it to the new file:
Private void DownAttachment ()
// Service1WSE: Microsoft. Web. Services. WebServicesClientProtocol the Service1 here inherits the class in WSE
Service1WSE sw = new Service1WSE ();
// Obtain the attachment from webservice
Sw. GetAttachment ();
// Obtain the stream of the attachment
Stream str = sw. ResponseSoapContext. Attachments [0]. Stream;
Int length = (int) str. Length;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.