Example of using the httpwebrequest class to call Web Services (C #)

Source: Internet
Author: User

PreviousArticleThis is about the C # Implementation of cmpp3.0. In order to test the provision interface, I used system. net. the httpwebrequest class sends the sample XML in the MISC system Short Message SP access guide-interface transformation sub-book to the Web service, and returns the corresponding resp package (also a piece of XML) from the web service ), next we willCodePost it:

1. XML content of the syncorderrelationreq package:

 

Code
< SOAP-ENV: Envelope Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance" Xmlns: XSD = "Http://www.w3.org/2001/XMLSchema" Xmlns: SOAP-ENV = "Http://schemas.xmlsoap.org/soap/envelope" Xmlns: SOAP-ENC = "Http://schemas.xmlsoap.org/soap/encoding" >
< SOAP-ENV: Header >
< Transactionid Xmlns = "Http://www.monternet.com/dsmp/schemas" > 00110318384464 </ Transactionid >
</ SOAP-ENV: Header >
< SOAP-ENV: Body >
< Syncorderrelationreq Xmlns = "Http://www.monternet.com/dsmp/schemas" >
< Version > 1.5.0 </ Version >
< Msgtype > Syncorderrelationreq </ Msgtype >
< Send_address >
< Devicetype > 0 </ Devicetype >
< DeviceID > 0011 </ DeviceID >
</ Send_address >
< Dest_address >
< Devicetype > 400 </ Devicetype >
< DeviceID > 0 </ DeviceID >
</ Dest_address >
< Feeuser_id >
< Useridtype > 1 </ Useridtype >
< Msisdn > 13456781234 </ Msisdn >
< Pseudo Code > </ Pseudo Code >
</ Feeuser_id >
< Destuser_id >
< Useridtype > 1 </ Useridtype >
< Msisdn > 13456781234 </ Msisdn >
< Pseudo Code > </ Pseudo Code >
</ Destuser_id >
< Linkid > SP </ Linkid >
< Actionid > 1 </ Actionid >
< Actionreasonid > 1 </ Actionreasonid >
< Spid > 419000 </ Spid >
< Spserviceid > -Yyxxyyxx </ Spserviceid >
< Accessmode > 3 </ Accessmode >
< Featurestr > Mta2njixndqgree = </ Featurestr >
</ Syncorderrelationreq >
</ SOAP-ENV: Body >
</ SOAP-ENV: Envelope > 2. httpwebrequest: Code
System. xml. xmldocument Doc =   New Xmldocument ();
Doc. Load ( " C: \ syncorderrelationreq. xml " );
Memorystream MS =   New Memorystream ();
Doc. Save (MS );

System. net. httpwebrequest R=(System. net. httpwebrequest) system. net. webrequest. Create ("Http: // localhost/websrv/dsmp. asmx");

R. Method =   " Post " ;
R. contenttype =   @" Text/XML; charset = UTF-8 " ;
R. headers. Add ( " Soapaction " , " \ "" + " Sim. syncorderrelation " + " \ "" );
R. Credentials = System. net. credentialcache. defaultcredentials;

Byte[] Bytes=Ms. toarray ();
R. contentlength=Bytes. length;
Stream s=R. getrequeststream ();
S. Write (bytes,0, Bytes. Length );
S. Close ();

streamreader Sr = New streamreader (R. getresponse (). getresponsestream ();
string retxml = Sr. readtoend ();
Sr. close ();
doc = New xmldocument ();
Doc. loadxml (retxml);
Doc. save ( " C :\\ syncorderrelationresp. XML " ); This is only a small example of using httpwebrequest to call the web service. You only need to save the preceding XML file as syncorderrel in drive C. In the ationreq. xml file, the results returned by the web service are saved in syncorderrelationresp. xml of drive C.

Related Article

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: info-contact@alibabacloud.com 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.