示例:调用webservice查询IP地址信息
webservice地址:http://www.wjg121.cn/Service/IPAddress.asmx?op=GetIPCountryAndLocal
static void Main(string[] args) { //构造soap请求信息 StringBuilder soap = new StringBuilder(); soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); soap.Append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"); soap.Append("<soap:Body>"); soap.Append("<GetIPCountryAndLocal xmlns=\"http://tempuri.org/\">"); soap.Append("<RequestIP>183.39.119.90</RequestIP>"); soap.Append("</GetIPCountryAndLocal>"); soap.Append("</soap:Body>"); soap.Append("</soap:Envelope>"); string url = "http://www.wjg121.cn/Service/IPAddress.asmx"; Console.WriteLine(WebServiceUtility.GetSOAPReSource(url,soap.ToString())); Console.ReadKey(); }
//返回结果:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetIPCountryAndLocalResponse xmlns="http://tempuri.org/"><GetIPCountryAndLocalResult>广东省电信</GetIPCountryAndLocalResult></GetIPCountryAndLocalResponse></soap:Body></soap:Envelope>