Check if a web service is available
-
Does anyone know what's the best way to determine if a web service is available before you consume it each time?? For example, if anapplication can be used when it is either connected or disconnected. When it is disconnected, what error handling should be done? please show me a sample code. Thank you. Boo
-
Does anyone know what's the best way to determine if a web service is available before you consume it each time?? For example, if anapplication can be used when it is either connected or disconnected. When it is disconnected, what error handling should be done? please show me a sample code. Thank you. Boo
When instantiating the proxy class in your local app and calling a method, just put it in a try-catch block and catch exceptions. It is not the proxy's responsibility to connect the client machine, merely to marshal data and send it across the wire. An exception will be thrown when you instantiate the proxy class.
Microsoft MVP, Visual C# My Articles
-
When instantiating the proxy class in your local app and calling a method, just put it in a try-catch block and catch exceptions. It is not the proxy's responsibility to connect the client machine, merely to marshal data and send it across the wire. An exception will be thrown when you instantiate the proxy class.
Microsoft MVP, Visual C# My Articles
I wanted to make sure the methods are available before calling any. This is what I did, do you think it's good enough? wsABC = new SomeWebService.Service(); try { WebRequest myRequest = WebRequest.Create(wsABC.Url); WebResponse myResponse = myRequest.GetResponse(); } catch (WebException ex) { if(ex.Status != WebExceptionStatus.Success) { String ExMsg="Exception Code : "+ ex.Status.ToString() + "\n" + "Exception Description : "+ ex.Message); MessageBox.Show(ExMsg); } } Thanks, Boo
-
I wanted to make sure the methods are available before calling any. This is what I did, do you think it's good enough? wsABC = new SomeWebService.Service(); try { WebRequest myRequest = WebRequest.Create(wsABC.Url); WebResponse myResponse = myRequest.GetResponse(); } catch (WebException ex) { if(ex.Status != WebExceptionStatus.Success) { String ExMsg="Exception Code : "+ ex.Status.ToString() + "\n" + "Exception Description : "+ ex.Message); MessageBox.Show(ExMsg); } } Thanks, Boo
You wouldn't even necessarily have to display an error if all you were doing is checking the connection, although you should always wrap your remote requests in a try-catch in case an error does happen. You should display a more user-friendly error, though. Taking this into account, why even bother to check the connection before hand? Just run the method. If it doesn't work, you display an error. Even if you were connected and for some reason the web service can't respond, doesn't respond correctly, or a myriad of other errors, you still want to display an error (or react accordingly).
Microsoft MVP, Visual C# My Articles
-
You wouldn't even necessarily have to display an error if all you were doing is checking the connection, although you should always wrap your remote requests in a try-catch in case an error does happen. You should display a more user-friendly error, though. Taking this into account, why even bother to check the connection before hand? Just run the method. If it doesn't work, you display an error. Even if you were connected and for some reason the web service can't respond, doesn't respond correctly, or a myriad of other errors, you still want to display an error (or react accordingly).
Microsoft MVP, Visual C# My Articles
Oh, that was just a sample I'm working on. I don't think I'll show the error in the actual app. and I do plan on using the try and catch each time calling the methods. The reason I wanted to make sure there is a connection is that if the app is used offline, it does different thing and won't allow to call any of the webservice's methods anymore. As far as handling other errors from the webservices, it's a different issue. Thank you for your advice. =) Boo