How to check if web service is available without using credentials
How to check if web service is available without using credentials
I have a WPF app written in c# and it is supposed to work in offline and online both. I have a class that checks for connectivity to web service using following skeleton code :-
var url = "https://somesite.com/mywebservice.svc";
var myRequest = (HttpWebRequest)WebRequest.Create(url);
var response = (HttpWebResponse)myRequest.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Debug.Write(string.Format("{0} Available", url));
}
else
{
// error
}
The issue is the web service requires authentication and hence an "unauthorized" exception is always thrown. Although the exception means the service is available but it is logged at network level and causes security alarm as the check is every 10 seconds. Is there a way to check the authenticated service availability without use of credentials or any other solution to above problem?
Thank you for the help!
btw, you could send basic auth credentials stackoverflow.com/questions/4334521/…
– Mate
Jul 2 at 4:11
How do you define available? That the port is open, or that you get a valid http response?
– cricket_007
Jul 2 at 4:14
@Mate i don't want to hard-code credentials as it is some what unsafe; I can add a new method but I believe anonymous access to method will also be not allowed as the service is authenticated.
– AjS
Jul 2 at 4:14
@Mate is right. Also OP make sure you close the Response object otherwise it works intermittently, Ref stackoverflow.com/a/3939689/495455
– Jeremy Thompson
Jul 2 at 4:27
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you change the webservice? add a new method?
– Mate
Jul 2 at 4:10