D A V I D M A D D I S O N
Flex and Workshop Conversational WebServices

Introduction

In a previous article I explained the wire format required to communicate with a conversational WebService. Here I expand on that to show how a Macromedia Flex application can be used to communicate with a Workshop Conversational WebService.

Using the techniques here will allow you to build RIA interfaces to your Weblogic Integration Applications.

The WebService declaration

In order to access a WebService in Flex, you have to specify the mx:WebService tag along with the various methods.

The following shows an example mx:WebService declaration:

<mx:WebService wsdl="http://localhost:7001/WorkshopTests/TestConversational.jws?WSDL"
                           id="ConverstationalWS"
                           service="TestConversational"
                           port="TestConversationalSoap"
                           useProxy="false"
                           load="setupHeaders()">
        <mx:operation name="StartMethod" result="alert(event.result)"/>
        <mx:operation name="ContinueMethod" result="alert(event.result)"/>
        <mx:operation name="FinishMethod" result="alert(event.result)"/>
</mx:WebService>

Adding the required SOAP headers

You'll notice in the previous code that I've included the setupHeaders() call when the WebService proxy gets created. This method is responsible for setting up the StartHeader and ContinueHeader to be used when contacting the WebService.

The following code shows the implementation of this function:

/* Global variables */
var startHeader;
var continueHeader;
var conversationID="1234567893";

function setupHeaders() {
  var startQName = new mx.services.QName("StartHeader",
           "http://www.openuri.org/2002/04/soap/conversation/");
  startHeader = new mx.services.SOAPHeader(startQName, 
           {conversationID:conversationID,callbackURL:"localhost"});

  var continueQName = new mx.services.QName("ContinueHeader",
           "http://www.openuri.org/2002/04/soap/conversation/");
  continueHeader = new mx.services.SOAPHeader(continueQName, 
           {conversationID:conversationID});
}

The first part of each header setup creates a QName which corresponds to the full name of each header, for example http://www.openuri.org/2002/04/soap/conversation/:StartHeader. This QName is important to the call and should be exactly as specified here. Any other value for the namespace and Workshop will not recognise the SOAP header.

The second part of each header setup creates the actual header with certain properties. In the case of the start header, it creates the SOAPHeader passing in a set of properties with conversationID and callbackURL.

Calling Conversational Methods

Since the headers will be created and stored in global variables, all that's required is to attach the correct header to each WebService call. For simplicity I've created local functions which mirror the WebService functions. When called, these local functions will automatically append the correct header before invoking the WebService method

The following code shows how to call a start method;

function StartMethod(name) {

  /* Make sure there are no other headers on this call */
  ConverstationalWS.clearHeaders();

  /* Add Start Header */
  ConverstationalWS.addHeader(startHeader);

  /* Call WebService Method */
  ConverstationalWS.StartMethod(name);
}

Putting it all together

The following shows how all this is put together into one test application:

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" height="600">

    <mx:Script>
        var startHeader;
        var continueHeader;
        var conversationID="12345678932";

        function setupHeaders() {
            var startQName = new mx.services.QName("StartHeader",
            "http://www.openuri.org/2002/04/soap/conversation/");
            startHeader = new mx.services.SOAPHeader(startQName,
            {conversationID:conversationID,callbackURL:"localhost"});

            var continueQName = new mx.services.QName("ContinueHeader",
            "http://www.openuri.org/2002/04/soap/conversation/");
            continueHeader = new mx.services.SOAPHeader(continueQName,
            {conversationID:conversationID});
        }

        /* Add stuff and make the calls */
        function StartMethod(name) {

            ConversationalWS.clearHeaders();

            /* Add Start Header */
            ConversationalWS.addHeader(startHeader);
            ConversationalWS.StartMethod(name);
        }

        function ContinueMethod() {

            ConversationalWS.clearHeaders();

            /* Add Continue Header */
            ConversationalWS.addHeader(continueHeader);
            ConversationalWS.ContinueMethod();
        }

        function FinishMethod() {

            ConversationalWS.clearHeaders();

            /* Add Continue Header */
            ConversationalWS.addHeader(continueHeader);
            ConversationalWS.FinishMethod();
        }
    </mx:Script>

    <mx:WebService wsdl="http://maddison02:6001/LocalClarifyStats/TestConversational.jws?WSDL"
                   id="ConversationalWS"
                   service="TestConversational"
                   port="TestConversationalSoap"
                   useProxy="false"
                   load="setupHeaders()">

        <mx:operation name="StartMethod" result="alert(event.result)"/>
        <mx:operation name="ContinueMethod" result="alert(event.result)"/>
        <mx:operation name="FinishMethod" result="alert(event.result)"/>
    </mx:WebService>

    <mx:TitleWindow label="Conversataional WS Test">
        <mx:Button label="Start Conversation" click="StartMethod('dave');"/>
        <mx:Button label="Continue Conversation" click="ContinueMethod();"/>
        <mx:Button label="Finish Conversation" click="FinishMethod();"/>
    </mx:TitleWindow>

</mx:Application>

For completeness, here's a copy of the WebService to which this application would connect:

public class TestConversational implements com.bea.jws.WebService
{
    static final long serialVersionUID = 1L;

    String _name;

    /**
     * @common:operation
     * @jws:conversation phase="start"
     */
    public String StartMethod(String name)
    {
        _name = name;

        return "Hello From Start Method";
    }

    /**
     * @common:operation
     * @jws:conversation phase="continue"
     */
    public String ContinueMethod()
    {
        return _name;
    }

    /**
     * @common:operation
     * @jws:conversation phase="finish"
     */
    public String FinishMethod()
    {
        return "Conversation Ending!";
    }
}

Comments:

Post a comment:
Name: *
email: *
url:
Comment
 
 
- BEA Weblogic Workshop
- ColdFusion
- Flex
- Other Stuff
 
- BEA Workshop
- FREE Workshop Licenses

- Macromedia Flex
- Macromedia ColdFusion

- UK CFUG Blog Aggregator