WebService is very simple to use, the main use of the Internet can follow based tutorial reference, that is, adding that a web application;
Can then be used directly in the project, another project in the same solution in the "referral service", this step there should be noted;
Remember that before referral service to compile just fine, otherwise it will not be referenced;
webservice would like to have a ratio of webapi what good is it?
It is really quite easy to operate, the equivalent of a direct call function;
Refer to the following uses:
. 1 WeatherWSSoap WS = new new WeatherWSSoapClient (); // custom namespace 2 String [] = A ws.getRegionProvince (); // call the method . 3 the foreach ( var Item in A) . 4 { . 5 (Item) Console.WriteLine; . 6 } . 7 . 8 the try . 9 { 10 MyCustomSoapClient MC = new new MyCustomSoapClient (); // local WebService . 11 Console.WriteLine (mc.HelloWorld ()); // call the method 12 is } 13 is the catch (Exception EX) 14 { 15 Console.WriteLine(ex.Message); 16 throw; 17 }
Here I am using a webservice http://ws.webxml.com.cn/WebServices/WeatherWS.asmx this address;
----------------------------------------
Of course, you can also use httpwebrequest access, but this may not quite have the maneuverability is not recommended!
code show as below:
1 HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince"); 2 req.Method = "GET"; 3 4 HttpWebResponse res = (HttpWebResponse)req.GetResponse(); 5 Stream resStream = res.GetResponseStream(); 6 StreamReader strReader = new StreamReader(resStream, Encoding.UTF8); 7 string data = strReader.ReadToEnd(); 8 Console.WriteLine(data);