How to throw a exception if something goes wrong?

  • Thread starter Thread starter guptatushar
  • Start date Start date
G

guptatushar

I have a Webservice which calls another component sitting on different
machine

Machine A Machine B
Webservice ------------------->Component

Due to network problem when webservice calls component it kinds of
hung. I want to give a timeout to it and if within that timeout
period nothing comes back just throw exception. Any one can give me
an idea how to accomplish it.
Thanks
 
You could set a timeout value for your webservice call and see if that
helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebServicesProtocolsWebClientProtocolClassTimeoutTopic.asp

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP


guptatushar said:
I have a Webservice which calls another component sitting on different
machine

Machine A Machine B
Webservice ------------------->Component

Due to network problem when webservice calls component it kinds of
hung. I want to give a timeout to it and if within that timeout
period nothing comes back just throw exception. Any one can give me
an idea how to accomplish it.
Thanks
 
Thanks john for the reply, is there a way we could set the attribute
of WebMEthod so that if it dosent return in some specified time
throw an exception. I have a Webmethod somehting like this


[WebMethod]
public int GetTTMainframe1Status( out int Status)
{
int RetCode = -1;
Status = -1;
try
{
OSVC_NETWORKLib.MonitorNetworkClass MnfObj = new
OSVC_NETWORKLib.MonitorNetworkClass();
RetCode = MnfObj.Ping(0);
Status = RetCode;


}
catch(Exception ex)
{
EventLog.WriteEntry("AppMonitor",ex.ToString(),System.Diagnostics.EventLogEntryType.Error);
return Error;

}


I am having problem with Ping, when network is down. Can we set some
timeperiod to this Webmethod so that if ping gets called and
something is not returned back throw exception or just return. Any
help highly appreciated.
 
I dont think there us as such. The timout is how long the client proxy is
prepared to wait for a reply, not how long the web method can take to
execute.

Two options spring to mind ...

Put your call in a thread within the webmethod, and time it - aborting the
thread if it doesn't return in time and returning a sensible value to
indicate failure..

Or...set the session timout value in your web.config to be 1 minute, that
should timeout your method after 60 seconds. Of course with this you will
need to put your service in its own little application.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP



guptatushar said:
Thanks john for the reply, is there a way we could set the attribute
of WebMEthod so that if it dosent return in some specified time
throw an exception. I have a Webmethod somehting like this


[WebMethod]
public int GetTTMainframe1Status( out int Status)
{
int RetCode = -1;
Status = -1;
try
{
OSVC_NETWORKLib.MonitorNetworkClass MnfObj = new
OSVC_NETWORKLib.MonitorNetworkClass();
RetCode = MnfObj.Ping(0);
Status = RetCode;


}
catch(Exception ex)
{
EventLog.WriteEntry("AppMonitor",ex.ToString(),System.Diagnostics.EventLogEn
tryType.Error);
return Error;

}


I am having problem with Ping, when network is down. Can we set some
timeperiod to this Webmethod so that if ping gets called and
something is not returned back throw exception or just return. Any
help highly appreciated.
 
Back
Top