gpt4 book ai didi

java - 如何通过 Axis2 使用 Web 服务

转载 作者:行者123 更新时间:2023-12-01 15:28:10 25 4
gpt4 key购买 nike

我当前正在尝试从我编写的 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);
}
}

我在这里做错了什么吗?我对使用网络服务还很陌生,所以请耐心等待。

谢谢!

最佳答案

您可以使用以下命令生成 stub ,然后一切就很简单

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

关于java - 如何通过 Axis2 使用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9918586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com