代码之家  ›  专栏  ›  技术社区  ›  Swamy g

如何从独立Java客户端调用web服务?

  •  0
  • Swamy g  · 技术社区  · 16 年前

    比如说,我有一个echo web服务正在运行 http://localhost:8080/axis2/services/Service1 . 此服务只是回显通过函数发送给它的字符串 echo() . 使用上述服务(service.wsdl)的wsdl,我(在eclipse中)生成了ServiceStub.java和ServiceCallbackHandler.java。有了这两个文件,我如何编写一个调用 echo(String some_word) 并收到回复?谢谢

    3 回复  |  直到 16 年前
        1
  •  0
  •   Pascal Thivent    16 年前
        2
  •  2
  •   Mark MacIver    16 年前

    http://www.soapui.org/

    将它指向WSDL,它将允许您调用Web服务方法。

        3
  •  0
  •   Bob Yoplait    16 年前

    大概是这样的:
    (另见: Axis2 Web Service (Tomcat v6)

    package com.gg.ws;
    
    import java.rmi.RemoteException;
    
    import com.gg.ws.ServiceStub.Echo;
    import com.gg.ws.ServiceStub.EchoResponse;
    
    
    public class WebServiceTest {
    
        public void callEcho() throws RemoteException {
    
            ServiceStub stub = new ServiceStub();
    
            Echo request = new Echo();
            request.setValue("Whatever");
            EchoResponse response = stub.echo(request);
            System.out.println(" echo call   response: " + response.get_return());
        }
    }