Re: Problem with Exception Handling using Web Services
From: Adrian Burka (adrian_at_pliner.com)
Date: 01/13/05
- Next message: john deviney: "Re: Inserting a SOAP Header in a client request"
- Previous message: Dilip Krishnan: "Re: Sharing Types between Webservice and Client"
- In reply to: Dilip Krishnan: "Re: Problem with Exception Handling using Web Services"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 13 Jan 2005 17:06:53 -0500
Dilip,
There are actually 2 methods being called here:
/* Check the password to ensure it's correct */
private void checkPassword(string password)
{
if (password != kPASSWORD)
{
throw new Exception("Invalid password");
}
}
/* Check the password first, and if it's ok, return an array of question IDs
for this session */
[WebMethod]
public int[] getQuestionArray(string password, string sessionID)
{
checkPassword(password);
// does whatever else it has to do; it never makes it past this line
when the wrong password is supplied
}
The Exception is definitely thrown, but when I run it in a web browser it
just returns "Invalid password" as text; no headers or anything like that.
I'm sure it sends the same data to my application... and since it's
expecting content-type text/xml, naturally I get my error.
I have also tried throwing a SoapException, following the MSDN example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebServicesProtocolsSoapExceptionClassTopic.asp
... but that yielded the exact same results, plain text output without
headers or XML formatting. The same thing happens if I throw an Exception --
or a SoapException -- directly from the getQuestionArray() WebMethod (as
opposed to throwing it from the private checkPassword() method.)
Dilip, thanks for taking a look -- here's hoping you have some insight!
Regards,
Adrian
"Dilip Krishnan" <dkrishnan@NOSPAM.geniant.com> wrote in message
news:150723632412280431277920@msnews.microsoft.com...
> Hello Adrian,
>
> Could you post the method?
> HTH
> Regards,
> Dilip Krishnan
> MCAD, MCSD.net
> dkrishnan at geniant dot com
> http://www.geniant.com
>
>> HELP! I have written a web service, and a program in C# using
>> Microsoft Visual C#.NET to interact with the web service. Exception
>> handling isn't working in my application, though.
>>
>> One function that is called checks to see if a password is correct,
>> and if it's not, it throws an exception with the message "Invalid
>> password".
>>
>> I have exception-handling code in my application, but it doesn't catch
>> the error I'm expecting. Instead, it catches the following exception:
>>
>> System.InvalidOperationException: Client found response content type
>> of '', but expected 'text/xml'.
>>
>> When I access the web service through a browser and execute the
>> function, it returns the text "Invalid password" and that's it; it
>> doesn't appear to be wrapped in any sort of XML/SOAP exception-type
>> object.
>>
>> So, apparently, I'm not receiving an object, just a string of text. I
>> can't figure out how to properly catch an exception, nor can I figure
>> out how to access that text. Any ideas on how to fix this the correct
>> way or, if not the correct way, at least how to access the error text
>> that is returned so that when I see "System.InvalidOperationException:
>> Client found response content type of '', but expected 'text/xml'"
>> I'll know it's an error and will be able to process the text (and
>> therefore the error)?
>>
>> Thanks in advance to anyone who knows the answer...!
>>
>> ---
>> Adrian Burka
>> Pliner Solutions, Inc
>> Your Internet Technology Partner
>> http://www.pliner.com
>> adrian@pliner.com
>
>
- Next message: john deviney: "Re: Inserting a SOAP Header in a client request"
- Previous message: Dilip Krishnan: "Re: Sharing Types between Webservice and Client"
- In reply to: Dilip Krishnan: "Re: Problem with Exception Handling using Web Services"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|