Flex AS3 call a Java Webservice

Flex AS3 call a Java Webservice


Webservice is a standard in soa architecture.
Flex is a leading tecnology for client side so let's see how actionscript 3(the flex programming language) can call a java(jax-ws) webservice.

Starting Point

The main step are:

  1. Make a WebProject with a Webservice
  2. Make a MXML in flex side and code the call

The webservice:

Two click with netbeans header and you can obtain this code:

package webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

public class testWS 
    @WebMethod(operationName = "sayHello")
    public String sayHello(@WebParam(name = "name")
    String name)
        return "hello " + name;


The Action Script Side inside mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" click="useWebService()">

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.WebService;
public function useWebService():void
var ws:WebService = new WebService();
private function onResult(event:ResultEvent):void
 trace("result " + event.result);
private function onFault(fault:FaultEvent):void
 trace("fault " + fault);

To see the result debug the flex application and see at console only after deploy the webservice.


This is the runtime version.

No comments: