January 03, 2004

EndpointReferences for Don

Don asks about a mechanism for setting the <wsa:To> header in a SoapEnvelope using recent WSE 2.0 bits. Here's some more sample code (as best I recall it):

EndpointReference r = ...;
SoapEnvelope e = ...;
//
// Set the destination for the SoapEnvelope
//
e.Context.Addressing.Destination = r;
//
// Set the real headers in the SoapEnvelope
//
e.Context.Addressing.GetXml(e);

The last line above adds all the WS-Addressing headers from the envelope's SoapContext into the SoapEnvelope itself. Now, it's also possible to declare an instance of AddressingHeaders directly and use that instead:

AddressingHeaders h = new AddressingHeaders();

h.Destination = r;

h.GetXml(e);

One thing that this mechanism doesn't do is remove any existing headers. This can be done another way:

SoapEnvelope e = ...;

//
// Load any addressing headers, but do not remove them
//
e.Context.Addressing.LoadXml(e);
//
// Remove the headers from the SoapEnvelope
//
e.Context.Addressing.RemoveXml(e);

Now, the mechanisms above are, to my mind, still quite clumsy and I'd prefer a different programming model that makes headers an intrinsic part of the SoapEnvelope itself. That's something that will have to wait for WSE 3.0.

Posted by herveyw at January 3, 2004 11:14 AM
Comments