Laden...

Eine bestimmte Ausnahme abfangen

Erstellt von f.ritz vor 18 Jahren Letzter Beitrag vor 18 Jahren 2.807 Views
f.ritz Themenstarter:in
341 Beiträge seit 2004
vor 18 Jahren
Eine bestimmte Ausnahme abfangen

Hallo!

Ich möchte folgendes realisieren:

Ich benutze auf mienen ASP.NET-Site ein WebServices das eine bestimmte Ausnahme(System.UnauthorizedAccessException) auslösen kann, ich kann aber diese nicht mit try-catch abfangen:

try
{
  wsProxy.anmeldung(name,password);
}
catch(System.UnauthorizedAccessException)
{
  /* Wird leider nicht ausgeführt */
}
catch(System.Web.Services.Protocols.SoapException)
{
  /* Wird ausgeführt, obwohl es sich um eine UnauthorizedAccessException handelt*/
}

In der Exception-Message steht dann:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.UnauthorizedAccessException:........ --- End of inner exception stack trace ---

Wie kann ich also apeziell die UnauthorizedAccessException vom WebService abfangen, obwohl eine SoapException ausgefürt wird.

V
327 Beiträge seit 2005
vor 18 Jahren

hallo,
mal sehen, ob ich das noch zusammen bekommen, meine MCP prüfungen sind noch nicht lange her... 😉
da du deinen web-services via SOAP anspricht und dieser auch mit SOAP antwortet, kann er dir doch auch nur eine SOAP-exception liefern, oder?

hier ist mal eine frage aus der prüfung, die so ähnlich ist. aber die erklärung ist gut denke ich.
vielleicht hilft das ein bißchen weiter
**
"20. QUESTION NO: 20
You are creating an ASP.NET application named WebApp. To WebApp,
you add a Web reference to an XML Web service named UserService.
UserService consists of a Web method named RetrieveUserInfo. This Web method takes
a userID as input and returns a DataSet object containing user information. If the
userID is not between the values 1 and 1000, a System ArgumentException is thrown.
In WebApp, you write a try/catch block to capture any exceptions that are thrown
by UserService. You invoke RetrieveUserInfo and pass 1001 as the user ID .

Which type of exception will be caught?

A. System.ApplicationException
B. System.ArgumentException
C. System.Web.Service.Protocols.SoapException
D. System.Web.Service.Protocols.SoapHeaderException

Answer: C

Explanation: The SoapException is thrown when an XML Web service method is called over
SOAP and an exception occurs.

Note: Simple Object Access Protocol (SOAP) codifies the practice of using XML and HTTP
to invoke methods across networks and computer platforms. SOAP is a XML-based protocol
that lets you activate applications or objects within an application across the Internet.
Reference: .NET Framework Class Library, SoapException Class"**
aber ich hab auch noch nie was mit web-services gemacht, kenn das nur aus dem kurs.

grüße von der küste

MFG Veasel

#
88 Beiträge seit 2005
vor 18 Jahren

Hallo f.ritz,

vielleicht hilft dir das:


try
{
    Foo();
}
catch (System.Web.Services.Protocols.SoapException e)
{
    if (e.InnerException == typeof(System.UnauthorizedAccessException))
    {
        // deine exception behandlung
    }
    else
        throw e;
}

f.ritz Themenstarter:in
341 Beiträge seit 2004
vor 18 Jahren

Ich habe nun ein Problem:

wenn ich mit e.InnerException die Exception abfrage dann wird die NullRefernezException ausgelöst!?!?!

Vielleicht löse ich die Exception beim WebService falsch aus:

throw new Exception("",System.UnauthorizedAccessException)
6.862 Beiträge seit 2003
vor 18 Jahren

Hab das jetzt nicht ausm Kopf aber müsstest du nicht nen Exceptionobjekt übergeben statt den Exceptionnamen?

Baka wa shinanakya naoranai.

Mein XING Profil.

f.ritz Themenstarter:in
341 Beiträge seit 2004
vor 18 Jahren

Stimmt!
Tip-Fehler, sieht in der wirklichkeit auch so aus:

throw new Exception("",new System.UnauthorizedAccessException())
F
10.010 Beiträge seit 2004
vor 18 Jahren

Also was willst Du nun, eine Exception oder eine UnauthorizedAccessException()

Das reicht.

throw new System.UnauthorizedAccessException()  
G
131 Beiträge seit 2005
vor 18 Jahren

Hallo,

Exception Management in .NET - paterns & practices Seite 16

Link: Exception Management in .NET

Web Services
Web services are limited in their ability to propagate exceptions using the Simple Object Access Protocol (SOAP). The .NET Framework provides the SoapException class as the only means to raise exceptions using SOAP. The CLR throws a SoapException automatically when it receives a malformed SOAP request from the client.

When a Web service method throws any unhandled exception, the exception is repackaged as a SoapException and is returned to the Web service client via the SOAP response. The ServerFaultCode is used to indicate that an error that was not a result of the message format or contents occurred during the processing of the request. The SOAP response that the server runtime creates is in a standard SOAP format allowing non-.NET clients to detect that an error has occurred. On a .NET-based client, the Framework captures the SOAP message and deserializes the SoapException so that the client can detect exceptions through standard exception handling techniques, just as it would for a non-Web service call. However, the exception that is detected on the client is a SoapException, not the exception type that was originally thrown by the Web service. Information about the original exception is included in the Message property of the SoapException.

f.ritz Themenstarter:in
341 Beiträge seit 2004
vor 18 Jahren

Original von Generalissimo
Information about the original exception is included in the Message property of the SoapException.

Soll also heißen, dass ich nur über das Filtern von Message-String-Eigenschaft, bestimmen kann welche Ausnahme wirklich ausgelöst wurde?
Hat es was mit Interoperabilität zutun?