当前位置: 代码迷 >> Web Service >> 有关webservice解决办法
  详细解决方案

有关webservice解决办法

热度:394   发布时间:2012-01-03 22:16:06.0
有关webservice
调用一个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);
} 
  相关解决方案