调用一个webservice服务,如何判断此服务是否可用。就是说如何判断是否此服务是否已经连接。
------解决方案--------------------
刚才试了Open对于错误的address居然没反映。
只好用WebClient来尝试连接。如果抛出WebException就有问题。
- C# code
try { var client = new ServiceReference1.Service1SoapClient("Service1Soap", "http://localhost:1985/Service3.asmx"); var wc = new WebClient(); var result = wc.DownloadString(client.Endpoint.Address.ToString()); Console.WriteLine("OK"); } catch (WebException webEx) { Console.WriteLine("ERR"); Console.WriteLine(webEx); } Console.WriteLine("-------------Spliter---------------"); try { var client = new ServiceReference1.Service1SoapClient("Service1Soap", "http://localhost:1983/Service1.asmx"); var wc = new WebClient(); var result = wc.DownloadString(client.Endpoint.Address.ToString()); Console.WriteLine("OK"); } catch (WebException webEx) { Console.WriteLine("ERR"); Console.WriteLine(webEx); }