2009-11-03 99 views
0

我有一個運行的回聲Web服務可以說http://localhost:8080/axis2/services/Service1。該服務只是回顯一個通過函數echo()發送給它的字符串。使用上述服務(Service.wsdl)的wsdl,我已經生成了(在eclipse中)ServiceStub.java和ServiceCallbackHandler.java。有了這兩個文件,我該如何編寫一個客戶端來調用echo(String some_word)並接收回應?謝謝。如何從獨立的Java客戶端調用Web服務?

回答

2

開始。如果你只是想測試/行使您的Web服務,我建議SOAPUI - http://www.soapui.org/

點它在你的WSDL,它將使你打電話給你Web服務方法。

0

事情是這樣的:
(參見: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()); 
    } 
}