Inconsistent SoapException.Message

D

djmc

Hi,



In my web application, I catch SoapExceptions and check the
SoapException.Message property to determine the error that occurred. For
instance, when authenticating a user, if the incorrect password is detected,
the following message is contained within SoapException.Message:

Password is incorrect for user



However, when I publish my web application to the production server (Using
Build/Publish Web Site in Visual Studio 2005 Pro RTM), SoapException.Message
returns:

System.Web.Services.Protocols.SoapException: Password is incorrect for user.
at SecureServices.AuthenticateUser(String username, String password)



This only happens when I publish the website. It does not occur when
testing locally. Could this be an inconsistency between IIS and Cassini?
Why would this happen? Also, if I am incorrectly passing errors back to my
web services client, please advise me on the correct way to do so. Here is
the code below that provides the above errors.



Web Service called:

[WebMethod]

public string AuthenticateUser(string username, string password)

{

string sAuthToken;

ErrorResponse response;



sAuthToken = UserLogic.AuthenticateUser(username, password, out response);



if (response.ResponseID != ErrorResponseIDs.Success)

throw new SoapException(response.ResponseMessage,
SoapException.ClientFaultCode);



return sAuthToken;

}







Web Service client that catches errors:

public static string AuthenticateUser(string username, string password, out
string errormessage)

{

string sAuthToken = "";

errormessage = null;



try

{

sAuthToken = ServicesGateway.SecureServices.AuthenticateUser(username,
password);

}

catch (SoapException se) { errormessage = se.Message; }



return sAuthToken;

}





Web Application that displays error (shortened):

protected void lbLogin_Click(object sender, EventArgs e)

{

string sErrorMessage, sAuthToken;



sAuthToken = AuthenticationLogic.AuthenticateUser(tbUsername.Text,
tbPassword.Text, out sErrorMessage);



if (sErrorMessage != null)

lMessage.Text = sErrorMessage; // Display error to Label control lMessage

}



Again, I am using Visual Studio 2005 Pro RTM. I have tried publishing using
pretty much every combination of options (Allow this precompiled site., Use
fixed naming. etc) both checked and unchecked. I will try to compile the
site using Beta 2 and see if this was an issue for me before and I just had
never noticed.



Anyways, hope someone can shed some light on what's going on here.

Thanks!

-DJ
 
D

djmc

Hi,

Go ahead and blame me for not using google first, but within 5 minutes I
found a solution to my problem. I found a blog with someone complaining
about the same junk wrapping around the original message in
SoapException.Message. In the comments section, someone writes:

"It is not intuitive, but you need to set the custom errors mode in your
web.config to On, not remote only or Off. This controls how your web service
errors are serialized as well as how errors are handled in asp.net apps.
you'll actually get the exception message you want and if you have an inner
exception, you'll get that message in the message as well (OuterMessage ->
inner exception message)."

The reason why this change worked for me is because my web services site is
hosted on the same machine as the other site that is using them. (Resulting
in customerrors off). However, my development machine, where I was
launching the site straight from visual studio, is on a separate machine so
I guess the customerrors on allows the soapexception to be serialized
appropriately without any of that junk wrapping my original message.

Anyways, I hope this helps whoever might come across this issue in the
future.
-DJ

Here's the blog with the comments that helped me figure out what was going
on here:
http://pluralsight.com/blogs/keith/archive/2005/06/02/9712.aspx
What's hilarious is that almost every post in the comments section seems to
ignore this easy fix and goes on to discuss creating soapexception wrappers
and such. Only two posts reference this fix, and one of them even asks if
everybody else missed the solution.


djmc said:
Hi,



In my web application, I catch SoapExceptions and check the
SoapException.Message property to determine the error that occurred. For
instance, when authenticating a user, if the incorrect password is
detected, the following message is contained within SoapException.Message:

Password is incorrect for user



However, when I publish my web application to the production server (Using
Build/Publish Web Site in Visual Studio 2005 Pro RTM),
SoapException.Message returns:

System.Web.Services.Protocols.SoapException: Password is incorrect for
user. at SecureServices.AuthenticateUser(String username, String password)



This only happens when I publish the website. It does not occur when
testing locally. Could this be an inconsistency between IIS and Cassini?
Why would this happen? Also, if I am incorrectly passing errors back to
my web services client, please advise me on the correct way to do so.
Here is the code below that provides the above errors.



Web Service called:

[WebMethod]

public string AuthenticateUser(string username, string password)

{

string sAuthToken;

ErrorResponse response;



sAuthToken = UserLogic.AuthenticateUser(username, password, out response);



if (response.ResponseID != ErrorResponseIDs.Success)

throw new SoapException(response.ResponseMessage,
SoapException.ClientFaultCode);



return sAuthToken;

}







Web Service client that catches errors:

public static string AuthenticateUser(string username, string password,
out string errormessage)

{

string sAuthToken = "";

errormessage = null;



try

{

sAuthToken = ServicesGateway.SecureServices.AuthenticateUser(username,
password);

}

catch (SoapException se) { errormessage = se.Message; }



return sAuthToken;

}





Web Application that displays error (shortened):

protected void lbLogin_Click(object sender, EventArgs e)

{

string sErrorMessage, sAuthToken;



sAuthToken = AuthenticationLogic.AuthenticateUser(tbUsername.Text,
tbPassword.Text, out sErrorMessage);



if (sErrorMessage != null)

lMessage.Text = sErrorMessage; // Display error to Label control lMessage

}



Again, I am using Visual Studio 2005 Pro RTM. I have tried publishing
using pretty much every combination of options (Allow this precompiled
site., Use fixed naming. etc) both checked and unchecked. I will try to
compile the site using Beta 2 and see if this was an issue for me before
and I just had never noticed.



Anyways, hope someone can shed some light on what's going on here.

Thanks!

-DJ
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top