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 :
291
ISoapMessage (RPC) Interface
There is not much more to know besides what we have seen
previously in order to generate RPC messages with the SoapFormatter. We passed objects to
the formatter’s Serialize()
method and it wrote a SOAP message to a stream. Generating SOAP messages works
just the same. The only new requirement is for the serialized object to
implement the ISoapMessage
interface, which is defined in the System.Runtime.Serialization.Formatters namespace.
The interface defines a set of properties to describe a SOAP RPC
message. Table 14.1 lists the properties and describes the purpose.
Table The SoapFormatter will serialize objects implementing
the ISoapMessage interface to RPC SOAP messages. We can control the contents of
the message through the interface’s properties.
Property
Type
Access
Description
Headers
Header[]
read/write
Adds and retrieves message headers, can be null.
MethodName
string
read/write
Specifies the name of the RPC method.
ParamNames
string[]
read/write
Specifies the names of the method’s parameters.
ParamTypes
Type[]
N/A
Reserved for future functionality
ParamValues
object[]
read/write
Specifies the values of the method’s parameters. The order
of the values must correspond to the order of the ParamNames.
XmlNameSpace
string
read/write
Specifies the XML
namespace for the method name. The namespace is declared by the publisher of
the RPC service.
Once more the .NET Framework provides us with a default
implementation of an interface. In this case it is the SoapMessage class implementing ISoapMessage.
When the SoapFormatter
detects this interface on an object passed to Serialize(), it only serializes the
data exposed through the interface’s properties. It ignores all other fields a
class might define.
Let’s go right ahead a write a class to send RPC messages. It’s
going to be very easy to develop the SoapRPCMessageSender because we still
only serialize objects through the SoapFormatter. With the original SoapObjectSender we already developed
a class to that can do exactly that.
By wrapping the SoapObjectSender’s generic SendObject() in another Send() method
that only accepts ISoapMessage
derived objects, the SoapRPCMessageSender
makes sure we do not send anything but objects implementing ISoapMessage to
the destination queue. Listing 14.1 shows the implementation of the SoapRPCMessageSender.
Listing A class to send SOAP RPC messages using the
SoapObjectSender
using System.Runtime.Serialization.Formatters;
class SoapRPCMessageSender
{
private SoapObjectSender
_Sender;
public
SoapRPCMessageSender( string destinationQueue )
{
_Sender = new
SoapObjectSender(destinationQueue);
}
public void Send(
ISoapMessage msg )
{
_Sender.SendObject(
msg );
}
}
There is nothing else new in the code snippet so we can move
right on to the next step: Marshal the method call with the parameters. In all
major distributed component technologies this task is typically performed by a
so-called proxy object behind the scenes. Proxies always expose the same
interface as the object they stand in for and forward (“marshal”) the
parameters of a method to the real object across the wire. The client cannot
tell the difference between invoking a method on a proxy or a local object.