By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Throwing a Soap Exception from a webservice

P: n/a
Hi,

I have written a web service for accessing data from a database. I have a
method in the webservice which returns a dataset. I am trying to implement
error handling by using the try...catch...finally structure.

Now, the method's logic in the try block returns a dataset while the the
code in the 'catch' block throws an exception object of the SoapException
class. Before, returning an exception to the calling code, I build up an
XML node structure and pass it to the constructor of the SoapException object.

What I expect to see is the Exception in an XML Format instead of the data
which being returned under normal circumstances. However, what I see is just
a 'HTTP 500 Internal Server Error. Page not displayed'. I have debugged the
code and it does go throught the catch block and the soapexception is
returned.

The outline for the code is as follows:

[WebMethod]
public DataSet ABC()
{
try
{
-
-
-
if (x<y)
{
return ds;
}
else
{
throw RaiseException(,,,,,,)
}

}
catch (SoapException soapEx)
{
EventLog.WriteEntry(soapEx.Source, soapEx.Message);
throw soapEx;
}
catch(Exception ex)
{
EventLog.WriteEntry(ex.Source, ex.Message);
throw
RaiseException("Para1", "Para2"
"Para3",Para4,"Para5",Para6,Para7);
}

}


public SoapException RaiseException(Para1,
Para2,
Para3,
Para4,
Para5,
Para6)
{
_
_
_
_
SoapException soapEx = new SoapException(errorMessage,
faultCodeLocation, uri,
rootNode);
//Raise the exception back to the caller
return soapEx;
}

}

Can I follow the approach above? i.e return a SoapException object in a
method of return type dataset or there is another way of doing it? Please
advise.

Cheers
Mar 18 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Just wanted to add that I am working on .Net 1.1

"Hemil" wrote:
Hi,

I have written a web service for accessing data from a database. I have a
method in the webservice which returns a dataset. I am trying to implement
error handling by using the try...catch...finally structure.

Now, the method's logic in the try block returns a dataset while the the
code in the 'catch' block throws an exception object of the SoapException
class. Before, returning an exception to the calling code, I build up an
XML node structure and pass it to the constructor of the SoapException object.

What I expect to see is the Exception in an XML Format instead of the data
which being returned under normal circumstances. However, what I see is just
a 'HTTP 500 Internal Server Error. Page not displayed'. I have debugged the
code and it does go throught the catch block and the soapexception is
returned.

The outline for the code is as follows:

[WebMethod]
public DataSet ABC()
{
try
{
-
-
-
if (x<y)
{
return ds;
}
else
{
throw RaiseException(,,,,,,)
}

}
catch (SoapException soapEx)
{
EventLog.WriteEntry(soapEx.Source, soapEx.Message);
throw soapEx;
}
catch(Exception ex)
{
EventLog.WriteEntry(ex.Source, ex.Message);
throw
RaiseException("Para1", "Para2"
"Para3",Para4,"Para5",Para6,Para7);
}

}


public SoapException RaiseException(Para1,
Para2,
Para3,
Para4,
Para5,
Para6)
{
_
_
_
_
SoapException soapEx = new SoapException(errorMessage,
faultCodeLocation, uri,
rootNode);
//Raise the exception back to the caller
return soapEx;
}

}

Can I follow the approach above? i.e return a SoapException object in a
method of return type dataset or there is another way of doing it? Please
advise.

Cheers
Mar 19 '07 #2

P: n/a
Hi,
If the client is using HTTP-GET or HTTP-POST, ASP.NET returns an HTTP
Internal Server Error (Error code 500) to the client.
Below two links elaborates more on this.
http://safari.peachpit.com/0735617201/IDAHVHT
http://msdn2.microsoft.com/en-us/library/aa480514.aspx
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Hemil" wrote:
Hi,

I have written a web service for accessing data from a database. I have a
method in the webservice which returns a dataset. I am trying to implement
error handling by using the try...catch...finally structure.

Now, the method's logic in the try block returns a dataset while the the
code in the 'catch' block throws an exception object of the SoapException
class. Before, returning an exception to the calling code, I build up an
XML node structure and pass it to the constructor of the SoapException object.

What I expect to see is the Exception in an XML Format instead of the data
which being returned under normal circumstances. However, what I see is just
a 'HTTP 500 Internal Server Error. Page not displayed'. I have debugged the
code and it does go throught the catch block and the soapexception is
returned.

The outline for the code is as follows:

[WebMethod]
public DataSet ABC()
{
try
{
-
-
-
if (x<y)
{
return ds;
}
else
{
throw RaiseException(,,,,,,)
}

}
catch (SoapException soapEx)
{
EventLog.WriteEntry(soapEx.Source, soapEx.Message);
throw soapEx;
}
catch(Exception ex)
{
EventLog.WriteEntry(ex.Source, ex.Message);
throw
RaiseException("Para1", "Para2"
"Para3",Para4,"Para5",Para6,Para7);
}

}


public SoapException RaiseException(Para1,
Para2,
Para3,
Para4,
Para5,
Para6)
{
_
_
_
_
SoapException soapEx = new SoapException(errorMessage,
faultCodeLocation, uri,
rootNode);
//Raise the exception back to the caller
return soapEx;
}

}

Can I follow the approach above? i.e return a SoapException object in a
method of return type dataset or there is another way of doing it? Please
advise.

Cheers
Mar 19 '07 #3

P: n/a
Hi Manish,

I read the msdn article and followed it. The problem in my case however is
that:

When, I try (for example)
Throw New Exception("Something bad happened")

It doesn't give me the following SOAP output as per what the article suggests.
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapExc eption: Server was
unable to process request. ---System.Exception: Something bad
happened at AYS17Sept2002.Service1.CallFault() in
c:\inetpub\wwwroot\AYS17Sept2002\Service1.asmx.vb: line 49
--- End of inner exception stack trace ---</faultstring>
<detail />
</soap:Fault>

Instead it gives me this:
Something bad happened.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Exception: Something bad happened

I understand that the asp.net asmx handler catches the exception and
transforms it into a SOAP fault. But it certainly isn't doing it in my setup.

Any ideas?
Cheers

"Manish Bafna" wrote:
Hi,
If the client is using HTTP-GET or HTTP-POST, ASP.NET returns an HTTP
Internal Server Error (Error code 500) to the client.
Below two links elaborates more on this.
http://safari.peachpit.com/0735617201/IDAHVHT
http://msdn2.microsoft.com/en-us/library/aa480514.aspx
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Hemil" wrote:
Hi,

I have written a web service for accessing data from a database. I have a
method in the webservice which returns a dataset. I am trying to implement
error handling by using the try...catch...finally structure.

Now, the method's logic in the try block returns a dataset while the the
code in the 'catch' block throws an exception object of the SoapException
class. Before, returning an exception to the calling code, I build up an
XML node structure and pass it to the constructor of the SoapException object.

What I expect to see is the Exception in an XML Format instead of the data
which being returned under normal circumstances. However, what I see is just
a 'HTTP 500 Internal Server Error. Page not displayed'. I have debugged the
code and it does go throught the catch block and the soapexception is
returned.

The outline for the code is as follows:

[WebMethod]
public DataSet ABC()
{
try
{
-
-
-
if (x<y)
{
return ds;
}
else
{
throw RaiseException(,,,,,,)
}

}
catch (SoapException soapEx)
{
EventLog.WriteEntry(soapEx.Source, soapEx.Message);
throw soapEx;
}
catch(Exception ex)
{
EventLog.WriteEntry(ex.Source, ex.Message);
throw
RaiseException("Para1", "Para2"
"Para3",Para4,"Para5",Para6,Para7);
}

}


public SoapException RaiseException(Para1,
Para2,
Para3,
Para4,
Para5,
Para6)
{
_
_
_
_
SoapException soapEx = new SoapException(errorMessage,
faultCodeLocation, uri,
rootNode);
//Raise the exception back to the caller
return soapEx;
}

}

Can I follow the approach above? i.e return a SoapException object in a
method of return type dataset or there is another way of doing it? Please
advise.

Cheers
Mar 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.