簡體   English   中英

如何在Axis2中使用Web服務

[英]How to use webservices with Axis2

我目前正在嘗試從編寫的Web應用程序中調用Web服務。 我的Web應用程序僅具有一個表單字段,該字段要求用戶在JSP頁面中提供電子郵件地址,然后將其發送到另一個名為process.jsp的JSP頁面進行處理。 在process.jsp中,我想調用一個Web服務,該服務將確認電子郵件地址的有效性。

我一直在嘗試調用此URL上的以下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 = "someEmail@hotmail.com";

    // 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);
} 
}

我在這里做錯什么了嗎? 我剛開始使用Web服務,所以請耐心等待。

謝謝!

您可以使用以下通用命令生成存根,然后一切都很容易

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM