简体   繁体   中英

How to use webservices with Axis2

I'm currently trying to invoke a web service from a web application that I've written. My web application simply has a form field that asks the user for an email address in a JSP page, sends it to another JSP page called process.jsp for processing. In process.jsp, I want to invoke a web service that will confirm the validity of the email address.

I've been attempting to invoke the following web service found at this URL:

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

My code below is as follows:

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

Is there something I'm doing wrong here? I'm very new to using web services, so please do be patient with me.

Thanks!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM