2012-03-29 92 views
0

我目前正在嘗試從我寫的Web應用程序調用Web服務。我的Web應用程序只有一個表單字段,它向用戶提供一個JSP頁面中的電子郵件地址,並將其發送到另一個名爲process.jsp的JSP頁面進行處理。在process.jsp中,我想調用一個Web服務來確認電子郵件地址的有效性。如何使用Web服務與Axis2

我一直在試圖調用以下Web服務發現這個網址:

http://www.xmethods.com/ve2/ViewListing.po?key=uuid:4506DD11-6A4F-2BF3-2DBE-EED251ABAA2A

下面我的代碼如下:

import javax.xml.namespace.QName; 
import org.apache.axis2.AxisFault; 
import org.apache.axis2.addressing.EndpointReference; 
import org.apache.axis2.client.Options; 
import org.apache.axis2.rpc.client.RPCServiceClient; 

public class ClientEmailValidate { 

public static void main(String[] args) throws AxisFault { 

    RPCServiceClient serviceClient = new RPCServiceClient(); 
    Options options = serviceClient.getOptions(); 

    // Setting the endpoint resource 
    EndpointReference targetEPR = new EndpointReference 
    ("http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx"); 
    options.setTo(targetEPR); 

    // Getting the operation based on the targetnamespace 
    QName opGetExchange = new QName        
      ("http://ws.cdyne.com", "VerifyEmail"); 

    String email = "[email protected]"; 

    // preparing the arguments 
    Object[] opGetExchangeArgs = new Object[] { email }; 

    // preparing the return type 
    Class[] returnTypes = new Class[] { String.class }; 

    // invoking the service passing in the arguments and getting the 
    // response 
    Object[] response = serviceClient.invokeBlocking(opGetExchange, 
      opGetExchangeArgs, returnTypes); 
    // obtaining the data from the response 
    String result = (String) response[0]; 

    // Displaying the result 
    System.out.println("Result : " + result); 
} 
} 

有什麼我做這裏錯了嗎?我對使用網絡服務非常陌生,所以請耐心等待。

謝謝!

+0

如果有選擇,我會使用JAXWS代替軸,它往往是一個有點簡單使用,它與jdk捆綁在一起。 – jtahlborn 2012-03-29 03:15:13

回答

1

您可以使用以下commond生成存根,那麼一切都容易

WSDL2Java -uri wsdl-url -p package-of-stub -d adb -s