How i can determine when a web service is available (on-line)? in Delphi or C#?
+4
A:
Try to use it. If it works, then it's available. If it doesn't, then it isn't (or you have network-connection problems between you and the server). There's no magic here.
Rob Kennedy
2009-06-28 23:21:29
+10
A:
Just do a valid call to the web service. If it times out, or you get a 404 error, the web service is not available.
Robert Harvey
2009-06-28 23:23:23
+2
A:
You can try this method..
public bool IsAddressAvailable(string address)
{
try
{
System.Net.WebClient client = new WebClient();
client.DownloadData(address);
return true;
}
catch
{
return false;
}
}
...and call it like this...
MessageBox.Show(IsAddressAvailable("http://localhost/my.webservices/mywebservice.asmx").ToString());
karbon
2009-06-29 00:05:59
+1
A:
Finally I Wrote this code in Delphi .Net
function WebService_OnLine(UrlWebService:String): Boolean;
Var
urlCheck : uri;
request : WebRequest;
response : WebResponse;
begin
MemoLogWebService.Lines.Add('Testing WebService');
urlCheck := Uri.Create(UrlWebService);
request := WebRequest.CreateDefault(urlCheck);
request.Timeout := 20000;
try
response :=request.GetResponse();
MemoLogWebService.Lines.Add(response.Headers.ToString);
Result:=True;
except
on E : Exception do
Begin
MemoLogWebService.Lines.Add(E.Message);
Result:=False;
End;
end;
End;
P.S : Thank you very much for giving me the inspiration.
RRUZ
2009-06-29 11:19:31
You should narrow your exception trap to communication based exceptions. You rarely if ever want to trap Exception since that could be a catastrophic error in addition to communication based exceptions.
Jim McKeeth
2009-06-29 15:59:20