Re: How to retrieve the soap payload in .NET/C# client

From: Derek Harmon (loresayer_at_msn.com)
Date: 03/04/04


Date: Wed, 3 Mar 2004 21:42:40 -0500


"Scott" <anonymous@discussions.microsoft.com> wrote in message news:653EF702-6ABE-48A0-BD71-8CA5DA91D901@microsoft.com...
> The client sends a request to a web sevice and gets a response back. Does anyone know
> how to retrieve the soap payload from the response? Usually the client will marshal the soap
> data into objects and I would assume there is a way to get the data before the marshalling
> process.

Yes, you can implement the abstract class, SoapExtension in the namespace
System.Web.Services.Protocols. The source code for a complete example,
very close to what you're looking for (it saves the SOAP request and response
to a file in the file system), is in the documentation for the SoapExtension class
in the .NET Framework SDK.

What essentially happens is your SoapExtension subclass implements the method
ProcessMessage( ) that gets called at various stages in the SOAP request/
response lifecycle. The SoapMessageStage you'd be interested in is Before-
Deserialize. Your ProcessMessage( ) method will be passed a SoapClientMessage
containing the envelope of the SOAP response.

In addition to coding a concrete subclass of SoapExtension (see the docs for the
complete source code of the TraceExtension), you must also create a custom
attribute with an AttributeUsage of AttributeTargets.Method. This attribute must
extend SoapExtensionAttribute like this,

    [AttributeUsage( AttributeTargets.Method)]
    public class MySoapExtensionAttribute : SoapExtensionAttribute {
        public override Type ExtensionType {
            get { return typeof( MySoapExtension); }
        }
        // . . .
    }

Here is how everything gets linked together:

1. In your proxy SoapHttpClientProtocol class, mark the client web methods
(those with SoapDocumentMethodAttributes) with MySoapExtensionAttribute.

2. At run-time, the .NET Framework will detect the presence of SoapExtension
attributes on your web method, and poll your custom MySoapExtensionAttribute
for its ExtensionType. This is why its important that property of the custom
attribute return the Type of MySoapExtension.

3. The Framework creates an instance of MySoapExtension, and calls its methods,
in particular ProcessMessage( ), at the various SoapMessageStages. This allows
your service client to capture the SOAP response envelope from a copy of the Web
Response stream.

Derek Harmon



Relevant Pages

  • SAAJ response - invalid SOAP envelope
    ... SOAP message to a servlet. ... The client receives the response and writes its content to ...
    (comp.lang.java)
  • Re: Client/Service relationships & Flow of Requirements.
    ... the client calls "foo" when it wants "bar" to return a particular value. ... The following is designed to compel Prey objects to do something: ... predator < 100 yards from prey ... It is the expectation of the response that makes the runFrom name immediately suspect in an OO context. ...
    (comp.object)
  • Re: [Full-disclosure] [Professional IT Security Providers -Exposed] PlanNetGroup ( F )
    ... the review a second time and incorporate some of your suggestions. ... to do what the client will pay him for. ... exactly a vulnerability assessment is... ... Your response to question 3: ...
    (Full-Disclosure)
  • deserialization arrays in Axis SOAP messages
    ... I have been trying to make requests of a web service provided by Axis using ... As a result of seraching news groups I guessed that the SOAP response ... defines an array element in a way that causes the dotnet deserialization ... I used SOAP extensions to manipulate the offending item in the SOAP ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: SOAP serialization problem
    ... I've snooped the SOAP response, ... this deserialization, but I've not found any that work. ... You're the client and you are the customer of a Web service that's for your use only. ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast