Serializing custom exception through a webmethod call.

Discussion in 'ASP .Net Web Services' started by Matt Bush, Nov 9, 2004.

  1. Matt Bush

    Matt Bush Guest

    How do I xml serialize a custom exception so it can be included as a
    parameter on my webmethod? See extra details below.

    I have an audit web service which attempts to log exceptions to a database.

    The web method looks like:

    <WebMethod(Description:="Log process message.")> _
    Public Function AddProcessMessage( _
    ByVal ProcessExecutionKey As Long, _
    ByVal AppEx As UserException) As Boolean

    ' Returns true if successfully logs the message and the AppEx log
    flag will also be set to true.
    Return ProcessExecution.AddProcessMessage(ProcessExecutionKey, AppEx )
    End Function

    This generates an error complaining about security permissions on the base
    exception class, eg. properties such as 'TargetSite' can not be serialised.

    Do I need to do imperative asserts or explicit demands or both. If so could
    you give me a code example that relaxes the security on xml serializing a
    custom exception.

    Thanks.
     
    Matt Bush, Nov 9, 2004
    #1
    1. Advertising

  2. Matt Bush

    Dan Rogers Guest

    Concur. Rather than base your types on the internal exception types (which
    are not portable), I'd suggest designing an exception base class of your
    own in XSD, just like you would design a business document such as an
    order. Then, generate classes from this XSD using XSD.exe or
    XSDObjectGen.exe, and build your service interface to accept the typed
    classes that result. This will give you the interface you need without
    introducing underlying platform item specific serialization issues.

    Regards,

    Dan Rogers
    Microsoft Corporation
    --------------------
    >Thread-Topic: Serializing custom exception through a webmethod call.
    >thread-index: AcTGqmaBU5DO+l+zRoKcjT3nv7Thwg==
    >X-WBNR-Posting-Host: 203.57.240.95
    >From: =?Utf-8?B?TWF0dCBCdXNo?= <Matt >
    >Subject: Serializing custom exception through a webmethod call.
    >Date: Tue, 9 Nov 2004 14:21:03 -0800
    >Lines: 25
    >Message-ID: <>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="Utf-8"
    >Content-Transfer-Encoding: 7bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >Content-Class: urn:content-classes:message
    >Importance: normal
    >Priority: normal
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
    >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
    >Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
    >Xref: cpmsftngxa10.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webservices:26429
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    >
    >How do I xml serialize a custom exception so it can be included as a
    >parameter on my webmethod? See extra details below.
    >
    >I have an audit web service which attempts to log exceptions to a database.
    >
    >The web method looks like:
    >
    > <WebMethod(Description:="Log process message.")> _
    > Public Function AddProcessMessage( _
    > ByVal ProcessExecutionKey As Long, _
    > ByVal AppEx As UserException) As Boolean
    >
    > ' Returns true if successfully logs the message and the AppEx log
    >flag will also be set to true.
    > Return ProcessExecution.AddProcessMessage(ProcessExecutionKey,

    AppEx )
    > End Function
    >
    >This generates an error complaining about security permissions on the base
    >exception class, eg. properties such as 'TargetSite' can not be serialised.
    >
    >Do I need to do imperative asserts or explicit demands or both. If so

    could
    >you give me a code example that relaxes the security on xml serializing a
    >custom exception.
    >
    >Thanks.
    >
     
    Dan Rogers, Nov 11, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Strange Exception with WebMethod

    Kevin Spencer, Oct 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    442
    Kevin Spencer
    Oct 28, 2004
  2. germ
    Replies:
    0
    Views:
    1,330
  3. Hendrik Maryns
    Replies:
    2
    Views:
    350
    John B. Matthews
    Dec 2, 2008
  4. Tobias Lekman

    Returning Enumeration or Exception from WebMethod?

    Tobias Lekman, Aug 9, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    176
    Marina
    Aug 11, 2003
  5. Matt
    Replies:
    1
    Views:
    162
Loading...

Share This Page