Throwing exception from web service .. catching by client

R

Raj

I catch and throw exception in a web service like the below way:

catch (Exception e)
{
throw new SoapException(e.Message,
SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
}

Whether the conventional method of catching exception at the client side
sufficient to handle the exception thrown by client?

catch (Exception e)
{
Console.WriteLine(e.Message);
}

Thank you

Regards
Raj
 
P

Peter Duniho

Raj said:
I catch and throw exception in a web service like the below way:

catch (Exception e)
{
throw new SoapException(e.Message,
SoapException.ServerFaultCode, Context.Request.Url.AbsoluteUri);
}

Whether the conventional method of catching exception at the client side
sufficient to handle the exception thrown by client?

I don't know the answer to your specific question. But you should not
throw a new exception from a catch block unless you include the current
exception as the inner exception for the new exception. For example:

catch (Exception e)
{
throw new SoapException(e.Message, SoapException.ServerFaultCode,
Context.Request.Url.AbsoluteUri, e);
}

Also, if you're going to generate a new exception like that, you really
ought to provide some added value to the message, rather than just
copying the one from the previous message.

As far as the specific question goes, I know almost nothing about web
services. But, your question seems to be asking whether an exception
thrown by the client will be caught by the client. My naïve expectation
is that of course it would. If you were asking about the exception
being transferred over the network from client to server or vice a
versa, then I could see it being less clear.

But an exception thrown in a thread of the client ought to be catchable
in the same thread of that client, just like exceptions generally.

Of course, you could easily test whatever scenario you're actually
interested, regardless of the specifics. Why you're asking the question
at all, I don't know. Why not just try it?

Pete
 
R

Raj

Let me explain the scenario:

A web service using Data provider need to catch the exception thrown by data
provider and return it to the web service consumer or return any exception in
the web service itself to the web service consumer.

Seems this is not happening, web service not catching exception thrown by
data provider.

Any workarounds...?

Thank you for your time, patience and efforts

Regards
Raj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top