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