Calling BPEL from C#
Thought I'd have a go at calling a BPEL process from C#. So I downloaded Microsoft Visual C# 2005 Express Edition this afternoon and got ready to fight the monster.
Well it turns out that the monster is a pussycat, it worked first time.
I took a simple BPEL process that takes two strings as input and returns a string and a boolean that indicate if they are the same or not. The appropriate input and output elements are:
<element name="EqualsProcessRequest">
<complexType>
<sequence>
<element name="delay" type="long"/>
<element name="input1" type="string"/>
<element name="input2" type="string"/>
</sequence>
</complexType>
</element>
<element name="EqualsProcessResponse">
<complexType>
<sequence>
<element name="equal" type="boolean"/>
<element name="same" type="string"/>
</sequence>
</complexType>
</element>
I fired up Visual C#, created a "Web Reference" to the BPEL process WSDL file. This created wrapper objects for the process and its variables. The default generation worked perfectly and the following C# code invoked the BPEL process.
String str1 = "String1";
String str2 = "String2";
EqualsBpelProcess.Equals bpel = new SimpleWebClient.EqualsBpelProcess.Equals();
EqualsBpelProcess.EqualsProcessRequest req = new SimpleWebClient.EqualsBpelProcess.EqualsProcessRequest();
req.input1 = str1;
req.input2 = str1;
EqualsBpelProcess.EqualsProcessResponse resp = bpel.process(req);
Console.WriteLine(str1+" = "+str2+" is "+resp.same+"("+resp.equal+")");
The above C# could probably be cleaner - this was my first C# application after all. Calling BPEL from C# is really that easy! The wonderful thing about web services is that the big companies have actually agreed on a useful standard.