Re: Problem with Exception Handling using Web Services

From: Adrian Burka (adrian_at_pliner.com)
Date: 01/13/05


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
>
>



Relevant Pages

  • Re: Asynchronous web service calls
    ... Some of the web method calls are probably failing - my guess is its the "The ... request failed with HTTP status 403" exception (i.e., ... private void btnRun_Click ... > I have a web service with 1 method: ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • SqlCeConnection
    ... I have two module level SqlCeConnection objects, ... error but the Exception object does not contain a message to display. ... private void CloseConnection() ... SqlCeCommand sqlCommand = null; ...
    (microsoft.public.sqlserver.ce)
  • Re: Write to IIS/Event Log File ?
    ... >with an exception that might arise, ... >either in the web service, ... >Writting to the event log threw me Security Exceptions, ... NET Framework Class Library: ApplicationActivationAttribute ...
    (microsoft.public.dotnet.general)
  • Re: Throwing Exceptions
    ... I just ran it and got the same result, it does not throw the exception! ... > private void InitializeComponent() ... > private void lblDest_DragDrop(object sender, ... >>> Create DragDrop event handler for label. ...
    (microsoft.public.dotnet.languages.csharp)
  • BeginExecuteReader doesnt work on one machine in my environment
    ... This exception is caught in the method, ... private delegate void loadReaderHandler(SqlDataReader sdr); ... private SqlConnection conn; ... private void aSynchTestHandler ...
    (microsoft.public.dotnet.framework.adonet)