What? A month went by already? December was pretty busy on the WSE team as we locked down and killed bugs to get to a stable build before the holiday period and I just didn't get much time to think about writing a blog entry. I also like to take a couple of weeks break so have been slack even though I've not been at work. Starting the New Year with some code seems appropriate.
public class EndpointReference : ICloneable, IComparable
{
//
// Implicit conversion from a Uri
//
public static implicit operator EndpointReference(Uri address);
//
// Explicit conversion to a Uri (lossy)
//
public static explicit operator Uri(EndpointReference endpoint);
public static bool operator == (EndpointReference ep1, EndpointReference ep2);
public static bool operator != (EndpointReference ep1, EndpointReference ep2);
public EndpointReference(Uri address);
public EndpointReference(Uri address, Uri transportAddress);
//
// Copy constructor
//
public EndpointReference(EndpointReference endpoint);
public object Clone();
public int CompareTo(object other);
public override bool Equals(object other);
public bool Matches(SoapEnvelope envelope);
public Uri Address { get; }
public ReferenceProperties ReferenceProperties { get; set; }
}
public class From : EndpointReference
{
...
}
public class ReplyTo : EndpointReference
{
...
}
public class FaultTo : EndpointReference
{
...
}
...
public static void Main()
{
EndpointReference epr = new EndpointReference( new Uri("urn:MyService"), new Uri("soap.tcp://localhost/MyService") );
SoapReceivers.Add(epr, new MyService());
}
The EndpointReference class replaces the EndpointReferenceType class from the WSE 2.0 Tech Preview and is a lot more extensive in its implementation for the final release.
First off, we have some conversion operators. Conversion from a Uri is implicit and sets the Address property. Conversion to a Uri is explicit since it's a lossy operation - you're dumping all the other data in the EndpointReference just to extract the Address property so you need to be explicit about doing that. We also added a copy constructor that makes it simpler to construct an EndpointReference from one of it's subclasses, for example when assigning the ReplyTo as the Destination of a message.
EndpointReference is now cloneable which helps parts of the messaging infrastructure by providing a (limited) barrier that prevents accidental changes to an object reference that is in use by the dispatching mechanism. What I really want from the CLR though is a simple mechanism to mark an entire object instance graph as read-only, in the same way that I want the CLR to provide a default deep-copy (thinks back to Smalltalk/V days long ago...).
The equality operators have been implemented along with a CompareTo method. Equality itself is a little tricky as EndpointReferences have an open-content model in the schema. I have modified the OpenContent classes quite a lot since the Tech Preview and this helps with serialization / deserialization but not much with comparison (where is XmlElement.Equals when you need it?). The only truly robust way to do the comparison is performing an XML canonicalization step but this is very expensive so instead we perform a more light-weight comparison that should serve just as well. Deep-tree comparisons will, however, be expensive operations. CompareTo is used when we use EndpointReferences in Hashtables with an EndpointReferenceComparer object; it's not really useful outside of this.
The Matches method is the current mechanism for determine whether the contents of a SoapEnvelope's <soap:Header> match an EndpointReference. It essentially looks for headers that match the Address property and then elements in the ReferenceProperties collection. I'll be looking at making the dispatch mechanism more robust next week (it needs a "best-match" algorithm) and thinking about whether the Match method needs to be pluggable to allow for user-defined comparisons.
Posted by herveyw at January 3, 2004 12:40 AMThis sounds like a great step forward over the tech preview, thanks
Posted by: Dave Angers at January 7, 2004 05:01 PM