浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

WS-ReliableMessaging interoperability between Microsoft WCF and Sun WSIT

src:http://weblogs.asp.net/gsusx/archive/2007/07/09/ws-reliablemessaging-interoprability-between-microsoft-wcf-and-sun-wsit.aspx

As promised I am going to start blogging about the different Web Services interoperability scenarios I represented as part of my session at SOAWorld 2007. I’ve decided to start with a
WS-ReliableMessaging scenario interoperability between Windows Communication Foundation (WCF) and Sun Project Tango (WSIT). The complete source code of this example can be downloaded from here. WS-ReliableMessaging (WS-RM) proposes a model based on SOAP messaging to achieve reliable communication between a service and its consumers. Although OASIS recently announced the version 1.1 the current implementations on .NET and Java environments are based on the previous version. As of today, technologies such as Microsoft WCF, BEA WebLogic, Sun WSIT, IBM WebSphere among others provides WS-RM implementations based on SOAP 1.1 and 1.2. However, similarly to other complex WS-* protocols, WS-RM interoperability represents a complex challenge that needs to be addressed in order to promote a wide adoption of this protocol. As I mentioned before there are several vendors that implement WS-RM Feb 2005. For the purposes of this sample I’ve decided to use Sun WSIT as the service provider and Microsoft WCF as the service consumer.

Show me the code!!

Implementing the WSIT service

Creating a Web Service using Sun WSIT is very similar to creating a Java class with a few annotations. The following code illustrated the WSIT service used as part of this demo. Just for this time, I’ve decided to give my readers a break and not implement a calculator so I went with the second most popular service contract in history.

@WebService()
public class EchoWS
{
    @WebMethod(action="Echo")
    public String Echo(String msg)
    {
        return msg;
    } 
}
 In order to add WS-RM capabilities to the service we have to configure a couple of sections in the Web Service configuration file.
<definitions
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="EchoWSService" targetNamespace="http://ws/" xmlns:tns="http://ws/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" xmlns:sunrm="http://sun.com/2006/03/rm"
 >
Other WSDL elements...
<service name="EchoWSService">
<wsdl:port name="EchoWSPort" binding="tns:EchoWSPortBinding"/>
</service>
<wsp:Policy wsu:Id="EchoWSPortBindingPolicy">
<wsp:ExactlyOne>
<wsp:All>
         <wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
<wsrm:RMAssertion/>
<sunrm:Ordered/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>

</definitions>
 

Implementing a WCF client

The first step for implementing a WCF client for the service created on the previous section is generating a WCF proxy using the svcutil.exe tool. After that, we can create the client logic as its showed in the following code.
private static void Test()
{
SimpleWSClient proxy = new SimpleWSClient();
Console.WriteLine(proxy.Echo("simple message 1"));
Console.ReadLine();
}
 
Finally we need to configure the client for supporting WS-RM. This is done adding the reliablesession section to the application configuration file. In order to achieve interoperability with Sun WSIT we’ve decided to rely on WS-Addressing 1.1.
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SimpleWSPortBinding">
<reliableSession maxPendingChannels="4" maxRetryCount="8" ordered="true" />
<!--Soap11WSAddressing10 encoding-->
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap11WSAddressing10" writeEncoding="utf-8" />
Other configuration elements....
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://wsitserver/EchoWSService?WSDL"
binding="customBinding" bindingConfiguration="SimpleWSPortBinding"
contract="SimpleWS" name="SimpleWSPort" />
</client>
</system.serviceModel>
</configuration>
 

Show me the messages!!

After deploying the service (we are using Sun Glassfish as the application server) and running the client the following SOAP message sequence is produced.  The first message, originated by WCF, requests the creation of a WS-RM sequence to group the messages that are going to be exchanged between the WCF client and the WSIT service.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action>
<a:MessageID>urn:uuid:c94288be-8c5e-450c-b5c1-9afa3dad727b</a:MessageID>
<a:To s:mustUnderstand="1">http://localhost:8080/WSApplication/EchoWSService?WSDL</a:To>
</s:Header>
<s:Body>
<CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm">
<AcksTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</AcksTo>
<Offer>
<Identifier>urn:uuid:e2addefe-af3c-4eac-af9c-181f8bacc827</Identifier>
</Offer>
</CreateSequence>

</s:Body>
</s:Envelope>
WS-RM Create Sequence message request

After receiving this message the WSIT engine replies with a sequence identifier.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://schemas.xmlsoap.org/ws/2005/02/rm/
CreateSequenceResponse
</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:3b34e870-f77b-4e81-803a-0fdaf7a03bd5</MessageID>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:c94288be-8c5e-450c-b5c1-9afa3dad727b</RelatesTo>
</S:Header>
<S:Body>
<ns2:CreateSequenceResponse xmlns:ns6="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns5="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>uuid:70429721-9229-4be5-b3af-0444f8f4e753</ns2:Identifier>
<ns2:Accept>
<ns2:AcksTo>
<ns4:Address>http://localhost:8080/WSApplication/EchoWSService?WSDL</ns4:Address>
</ns2:AcksTo>
</ns2:Accept>
</ns2:CreateSequenceResponse>

</S:Body>
</S:Envelope>
WS-RM Create Sequence response message

Now the WCF client produces the first message to invoke the Echo operation. The message is sent under the WS-RM session previously created and it is identified by a sequence number.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<r:Sequence s:mustUnderstand="1">
<r:Identifier>uuid:70429721-9229-4be5-b3af-0444f8f4e753</r:Identifier>
<r:MessageNumber>1</r:MessageNumber>

</r:Sequence>
<a:Action s:mustUnderstand="1">Echo</a:Action>
<a:MessageID>urn:uuid:d08a30f1-2364-4823-b7e7-af6f0eb8ebc1</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://localhost:8080/WSApplication/EchoWSService?WSDL</a:To>
</s:Header>
<s:Body>
<Echo xmlns="http://ws/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<arg0 xmlns="">simple message 1</arg0>
</Echo>
</s:Body>

</s:Envelope>

WS-RM Echo request

Finally the WSIT service produces the Echo response together with the acknowledgement for the Echo request.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://ws/EchoWS/EchoResponse</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:2e5673ab-aa45-495b-9711-51a7f77cd389</MessageID>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:d08a30f1-2364-4823-b7e7-af6f0eb8ebc1</RelatesTo>
<ns2:Sequence xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>urn:uuid:e2addefe-af3c-4eac-af9c-181f8bacc827</ns2:Identifier>
<ns2:MessageNumber>1</ns2:MessageNumber>

</ns2:Sequence>
<ns2:AckRequested xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>urn:uuid:e2addefe-af3c-4eac-af9c-181f8bacc827</ns2:Identifier>
</ns2:AckRequested>
<ns2:SequenceAcknowledgement xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>uuid:70429721-9229-4be5-b3af-0444f8f4e753</ns2:Identifier>
<ns2:AcknowledgementRange Upper="1" Lower="1"></ns2:AcknowledgementRange>
</ns2:SequenceAcknowledgement>

</S:Header>
<S:Body>
<ns2:EchoResponse xmlns:ns2="http://ws/">
<return>simple message 1</return>
</ns2:EchoResponse>
</S:Body>

</S:Envelope>
WS-RM Echo response and sequence acknowledgment message

Well, I hope that looked simple enough for illustrating a very complex WS interoperability problem. Obviously, real world enterprise service present complex message exchange patterns that require a careful design of the WS-RM sequences and acknowledgements.
One of the things I want to highlight is that although WS-RM represents the best Standard to exchange message in a reliable manner it is JUST NOT ENOUGH!! for real enterprise SOA scenarios. Other factors such as durable services, durable messaging, SLAs agreements among others need to be taken into consideration when comes to designing truly reliable services.

Where are we?

WS-RM is the most widely adopted protocol for achieving reliable communications between services and consumers. Although achieving WS-RM interoperability is challenging is different achievable with the current state of the WS-RM implementations. This article has showed how to achieve WS-RM interoperability between Sun WSIT and Microsoft WCF.

Published Monday, July 09, 2007 4:17 PM by gsusx

Comments

# WS-ReliableMessaging interoprability between Microsoft WCF and Sun WSIT - Jesus Rodriguez's WebLog

Pingback from  WS-ReliableMessaging interoprability between Microsoft WCF and Sun WSIT - Jesus Rodriguez's WebLog

Tuesday, July 10, 2007 3:20 PM by Arun Gupta's Blog

# GlassFish V2 Beta3 and Vista - Interoperable out-of-the-box

GlassFish V2 beta3 is now available. I take this opportune moment for a follow up entry showing how a Reliable WSIT endpoint can be invoked from WCF client and vice versa. WSIT is already integrated in GlassFish V2. The first...

Tuesday, July 10, 2007 3:21 PM by Arun

# re: WS-ReliableMessaging interoperability between Microsoft WCF and Sun WSIT

See the other part where a WSIT client invokes a WCF endpoint at: blogs.sun.com/.../glassfish_v2_beta3_and_vista

Wednesday, July 11, 2007 9:44 PM by Jesus Rodriguez's WebLog

# WS-ReliableMessaging interoperability between Microsoft WCF and Sun WSIT part II via Arun Gupta

It looks like I don’t need to post the second part of my WS-ReliableMessaging WCF WSIT interoperability

Tuesday, November 13, 2007 7:03 PM by Hermes

# re: WS-ReliableMessaging interoperability between Microsoft WCF and Sun WSIT

Interesting...

[URL=http://roberts-jeep.carcum.cn#">http://roberts-jeep.carcum.cn#] roberts jeep [/URL]

http://roberts-jeep.carcum.cn roberts jeep

posted on 2008-04-29 02:04  浙林龙哥  阅读(837)  评论(0编辑  收藏  举报