在flex和java中调用异步Web服务

时间:2013-04-30 06:48:31

标签: java web-services flex asynchronous

如何在java中访问我的异步Web服务?我在Flex Builder中做了这件事,而且非常简单:只需添加web服务,然后添加“数据 - >连接到Web服务 - >输入wsdl的URL”并添加以下行:

private function result(e:ResultEvent):void
{
     trace(e.result.toString());
}

private function fault(e:FaultEvent):void
{
     trace(e.toString());
}

var d:DomainAuth = new DomainAuth();
d.AuthFuncName(login, pass);
d.addEventListener(ResultEvent.RESULT, result);
d.addEventListener(FaultEvent.FAULT, fault);

如何使用eclipse EE在Java中执行此操作?

1 个答案:

答案 0 :(得分:0)

如果我理解正确的话,你基本上需要在java中使用SOAP Web服务客户端。 JAX-WS可以成为你的朋友。以下代码来自here

package simpleclient;

import javax.xml.ws.WebServiceRef;
import helloservice.endpoint.HelloService;
import helloservice.endpoint.Hello;

public class HelloClient {
    @WebServiceRef(wsdlLocation="http://localhost:8080/
        helloservice/hello?wsdl")
    static HelloService service;

  public static void main(String[] args) {
    try {
        HelloClient client = new HelloClient();
        client.doTest(args);
    } catch(Exception e) {
        e.printStackTrace();
    }
}

public void doTest(String[] args) {
    try {
        System.out.println("Retrieving the port from
                 the following service: " + service);
        Hello port = service.getHelloPort();
        System.out.println("Invoking the sayHello operation
                 on the port.");

        String name;
        if (args.length > 0) {
            name = args[0];
        } else {
            name = "No Name";
        }

        String response = port.sayHello(name);
        System.out.println(response);
    } catch(Exception e) {
        e.printStackTrace();
    }
  }
}