Re: How to retrieve the soap payload in .NET/C# client
From: Derek Harmon (loresayer_at_msn.com)
Date: 03/04/04
- Next message: Darius: "Hide StachTrace"
- Previous message: jpaz: "WSDL-Defined Faults"
- In reply to: Scott: "How to retrieve the soap payload in .NET/C# client"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Darius: "Hide StachTrace"
- Previous message: jpaz: "WSDL-Defined Faults"
- In reply to: Scott: "How to retrieve the soap payload in .NET/C# client"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|