Wednesday, September 30, 2009

Inter operating Apache Sandesah2 with WCF

Recently I have been working on interoperating WCF with the Apache Sandesha2. The good news is all the plain RM scenarios pass with some small fixings. Here is an sample client which can be used to invoke the wcf services available at http://131.107.72.15/endpoints/

First I generated the code for the given wsdl with wsdl2java tool with the following arguments

-uri http://10.100.1.238/ReliableMessaging_Service_WSAddressingAugust2004_Indigo/RequestReply.svc?wsdl
-u -ap -uw

-p org.wso2.carbon.interop.microsoft.rm.requestreply

-o target/generated-code

-Emp org.wso2.carbon.interop.microsoft.rm.requestreply

-ns2p http://tempuri.org/=org.wso2.carbon.interop.microsoft.rm.requestreply,http://schemas.microsoft.com/2003/10/Serialization/=org.wso2.carbon.interop.microsoft.rm.requestreply.types

Then we can simple invoke the service using the following client code.

// creating an configuration context which contains sandesah2 and addressing
ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("target" + File.separator +
"org.wso2.carbon.interop.microsoft.rm-SNAPSHOT.dir" +
File.separator + "repository");

EchoStringServiceCustomBinding_IEchoString9Stub stub = new EchoStringServiceCustomBinding_IEchoString9Stub(configurationContext,
"http://131.107.72.15/ReliableMessaging_Service_WSAddressingAugust2004_Indigo/RequestReply.svc/Reliable_Anonymous_Soap11_WSAddressingAugust2004_RM11");
// this is to send messages through tcp mon
stub._getServiceClient().getOptions().setProperty(Constants.Configuration.TRANSPORT_URL,
"http://localhost:8088/ReliableMessaging_Service_WSAddressingAugust2004_Indigo/RequestReply.svc/Reliable_Anonymous_Soap11_WSAddressingAugust2004_RM11");

// setting the correct addressing , soap and rm versions
stub._getServiceClient().getOptions().setProperty(AddressingConstants.WS_ADDRESSING_VERSION, AddressingConstants.Submission.WSA_NAMESPACE);
stub._getServiceClient().getOptions().setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
stub._getServiceClient().getOptions().setProperty(SandeshaClientConstants.RM_SPEC_VERSION, Sandesha2Constants.SPEC_VERSIONS.v1_1);

//wcf does not support make connections so disable it
Parameter sandeshaPolicyBeanParam = stub._getServiceClient().getAxisConfiguration().getParameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
if (sandeshaPolicyBeanParam != null) {
SandeshaPolicyBean sandeshaPolicyBean = (SandeshaPolicyBean) sandeshaPolicyBeanParam.getValue();
sandeshaPolicyBean.setEnableMakeConnection(false);
}

stub._getServiceClient().engageModule("addressing");
stub._getServiceClient().engageModule("sandesha2");

PingRequestBodyType pingRequestBodyType = new PingRequestBodyType();
pingRequestBodyType.setSequence("Sequence 1");
pingRequestBodyType.setText("testparam");
PingResponseBodyType pingResponseBodyType = null;
String responseString = "";
for (int i = 0; i < 3; i++) {
responseString += "testparam";
pingResponseBodyType = stub.echoString(pingRequestBodyType);
}

// after sending the messages we can close and terminate the sequence
SandeshaClient.closeSequence(stub._getServiceClient());
SandeshaClient.terminateSequence(stub._getServiceClient());

//wait until terminate sequence messge is send
SandeshaClient.waitUntilSequenceCompleted(stub._getServiceClient());

1 comment:

Unknown said...

Hi Amila,

I'm trying to use Axis2/Sandesha2 with the JDBC implementation of the StorageManager.

I have to make services reliables for the followings tests cases

1 Client UP - Server Down
- Client call a service
- Start the server
- The server answer the client

2 Client UP - Server Down
- Client call a service
- Shutdown the client
- Start the server
- Start the client
- The server answer the client

Could Sandesha2 answer this kind of demand ?

I have some issues with the actual version of Sandesha2. Could you please send me your samples and implementation of Sandesha2 ?

Best regards,
Youcef
yyekhlef@gmail.com