0

如何在 Java 中访问我的异步 Web 服务?我在 Flex Builder 中制作了这个东西,它非常简单:只需添加 web 服务 throw "Data -> Connect to Web Service -> Enter the URL of wsdl" 并添加以下行:

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 中做到这一点?

4

1 回答 1

0

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

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();
    }
  }
}
于 2013-04-30T09:53:44.630 回答