2012-03-29 132 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