# Step 3: Implement Asynchronous Communication

In this step you will enable asynchronous communication for the web service. You will add an asynchronous method that immediately returns a simple acknowledgement to the client, thereby allowing the client to continue its own processes. You will also add a callback method that returns the response to the client. Finally, you will add buffers to the method and the callback to further minimize the time the client or web service has to wait while the method invoked or callback returned is processed by the receiving party.

The tasks in this step are:

- Add a Method
- Add a Callback
- Edit the Method
- Add Buffers
- Test the Web Service

##
Add a Method

1. Right-click the web service in the main area and select Add Method.
2. The method newMethod1 appears. Rename this method hello_async. If you step off the method before you have finished renaming it, right-click the method and select Rename.
3. Make sure that hello_asynch is still selected and go to the Property Editor. Locate the conversation section and for the phase attribute, select start.
   A green start icon will appear on the blue arrow in front of the hello_asynch method.

## Add a Callback

1. Right-click the web service in the main area and select Add Callback.
2. The method newCallback1 appears. Rename this method hello_callback. If you step off the method before you have finished renaming it, right-click the method and select Rename.
3. Make sure that hello_callback is still selected and go to the Property Editor. Locate the conversation section and for the phase attribute, select finish.
   A red stop icon will appear on the blue arrow in front of the hello_callback method.
4. Click hello_callback to go to Source View and modify the method as shown in red below:

           public interface Callback extends com.bea.control.ServiceControl
           {
               /**
                * @jws:conversation phase="finish"
                */
               void hello_callback(String message);
           }

In Design View the web service should now look like this:

## Edit the Method

Now you will edit the hello_asynch method to invoke the hello_callback callback.

1. In Design View, click hello_asynch to go to Source View and modify the method as shown in red below:

           /**
            * @common:operation
            * @jws:conversation phase="start"
            */
           public void hello_asynch(String name)
           {
               String greeting;

               greeting = "Hello, " + name + "!";
               this.callback.hello_callback(greeting);
           }

## Add Buffers

1. Click the Design View tab.
2. In Design View, select the hello_asynch method by selecting the blue arrow in front of the method.
3. In the Property Editor, locate the message-buffer section and set the enable attribute to true. Notice that a buffer icon appears on the blue arrow.
4. In Design View, select the hello_callback method by selecting the blue arrow in front of the method.
5. In the Property Editor, locate the message-buffer section and set the enable attribute to true. Notice that a buffer icon appears on the blue arrow.

The completed web service should look like this:

## Test the Web Service

Next you will test the web service to examine its behavior.

1. Click the Start button, shown below:
2. When the Workshop Test Browser launches, in the Name field, enter [your_name] and click hello_asynch.
3. Notice that the method returns immediately. Scroll down to the Service Response section and notice that the method did not return anything. Also notice that the conversation has started.
4. Click the Continue this conversation link. Notice in the Message Log that the the hello_callback method has been invoked and that the conversation is finished. Also notice that no greeting is returned as a return value of the method; instead the callback method sends the greeting as a parameter to the invoking client.
5. Return to WebLogic Workshop and press the Stop button to close the Test Browser.

Click one of the following arrows to navigate through the tutorial: