C # invokes SOAP, WSDL by simulating an HTTP request

Source: Internet
Author: User

C # calls WebService a lot of the way I say this is called through HTTP request impersonation in order to solve the C # call Java Remote API a variety of incompatibility issues.

Since the remote API is not under our control, we can only modify the local calling code to accommodate the remote API.

In these cases, we call webservice by simulating an HTTP request.

First, we're going to parse the call port when we send out the data.

Grab a bag to see, here, we have no way to use Fiddler to listen to the contents of the SOAP protocol, but SOAP is based on the HTTP protocol.

You can catch it with a lower-level tool. Here can go to Baidu, a lot of tools.

But I found a Java-written gadget that listens to the SOAP protocol. "Poke me Download" http://download.csdn.net/detail/a406502972/9460758

After catching the bag, the direct post is OK, easy to understand, directly on the code:

1 Static stringdata =@"What to send";2 Private Static stringContentType ="text/xml; Charset=utf-8";3         Private Static stringAccept ="image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, Application/x-shockwave-flash, Application/x-silverlight, Application/vnd.ms-excel, Application/vnd.ms-powerpoint, Application/msword, Application/x-ms-application, APPLICATION/X-MS-XBAP, Application/vnd.ms-xpsdocument, Application/xaml+xml, APPLICATION/X-SILVERLIGHT-2-B1, */* ";4         Private Static stringUserAgent ="Axis2";5         /// <summary>6         ///Submit Data7         /// </summary>8         /// <param name= "url" ></param>9         /// <param name= "cookies" ></param>Ten         /// <param name= "param" ></param> One         /// <returns></returns> A          Public Static stringPostwebcontent (stringURL, Cookiecontainer cookie,stringparam) { -             byte[] bs =Encoding.ASCII.GetBytes (param); -             varHttpWebRequest =(HttpWebRequest) webrequest.create (URL); theHttpwebrequest.cookiecontainer =cookies; -Httpwebrequest.contenttype =ContentType; -Httpwebrequest.accept =Accept; -Httpwebrequest.useragent =useragent; +Httpwebrequest.method ="POST"; -Httpwebrequest.contentlength =BS. Length; +             using(Stream Reqstream =Httpwebrequest.getrequeststream ()) { AReqstream.write (BS,0, BS. Length); at             } -             varHttpWebResponse =(HttpWebResponse) httpwebrequest.getresponse (); -Stream Responsestream =Httpwebresponse.getresponsestream (); -             stringHTML =""; -             if(Responsestream! =NULL) { -StreamReader StreamReader =NewStreamReader (Responsestream, Encoding.UTF8); inHTML =streamreader.readtoend (); - streamreader.close (); to responsestream.close (); + Httpwebrequest.abort (); - httpwebresponse.close (); the             } *             returnhtml; $}

C # invokes SOAP, WSDL by simulating an HTTP request

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.