Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
285
Using the .NET SoapFormatter
SOAP RPC messages can carry message headers, just like regular
messages do. We learned how to add headers to document-style message in section
13.3.4 and we saw how complicated it is to extract them out of the message
later on. With RPC-style messages adding headers is just as easy as it was with
document-style messages, but retrieving them is a lot easier.
To add headers to an RPC message we have to assign an array of
Header objects to the Headers
property of the ISoapMessage
object we are serializing. These are the same Header objects from the System.Runtime.Remoting.Messaging
namespace we used to add header entries in section 13.3.4.1. However, when we
serialize an ISoapMessage
object the SoapFormatter
ignores any Header
object passed to the Serialize()
method. Only the headers in the array assigned to the Headers property of the ISoapMessage are
written to the generated message. The formatter will not even add Headers passed
to Serialize()
when the Headers
property on the interface is empty or set to null.
In our sender class we take the same approach we took previously
to add a transaction ID header entry. We add it inside the Send() method
like in the listing below.
Listing A Send() method to send RPC messages with headers
public void Send( ISoapMessage msg, long transactionId )
{
msg.Headers = new Header[] { new
Header("TransactionId",