加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Axis2调用WebService

发布时间:2020-12-16 22:16:55 所属栏目:安全 来源:网络整理
导读:jar包: axis2-1.7.1libaxiom-api-1.2.17.jar axiom-impl-1.2.17.jar axis2-kernel-1.7.1.jar axis2-adb-1.7.1.jar axis2-transport-local-1.7.1.jar axis2-transport-http-1.7.1.jar commons-io-2.1.jar httpcore-4.2.1.jar mail-1.4.jar commons-codec-1

jar包:

axis2-1.7.1libaxiom-api-1.2.17.jar
axiom-impl-1.2.17.jar
axis2-kernel-1.7.1.jar
axis2-adb-1.7.1.jar
axis2-transport-local-1.7.1.jar
axis2-transport-http-1.7.1.jar
commons-io-2.1.jar
httpcore-4.2.1.jar
mail-1.4.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
neethi-3.0.3.jar
wsdl4j-1.6.2.jar
xmlschema-core-2.2.1.jar
activation-1.1.jar
axiom-dom-1.2.17.jar
axis2-adb-codegen-1.7.1.jar
axis2-codegen-1.7.1.jar
axis2-java2wsdl-1.7.1.jar
geronimo-annotation_1.0_spec-1.1.jar
woden-core-1.0M10.jar

jar包下载地址:http://www.apache.org/dyn/closer.lua/axis/axis2/java/core/1.7.1/axis2-1.7.1-bin.zip

-----------------------------------------------------------默默无闻的分割线-----------------------------------------------------------

webService调用:

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;


public void getMobileCodeInfo()

? ? {?
? ??try?
? ? ? ? ?{?
? ? ? ? ? ? ?String soapBindingAddress = "http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl";?
? ? ? ? ? ? ?
? ? ? ? ? ? ?EndpointReference endpointReference = new EndpointReference(soapBindingAddress);?
? ? ? ? ? ? ?//创建一个OMFactory
? ? ? ? ? ? ?OMFactory factory = OMAbstractFactory.getOMFactory();?
? ? ? ? ? ? ?//指定命名空间
? ? ? ? ? ? ?OMNamespace namespace = factory.createOMNamespace("http://WebXml.com.cn/","web");?
? ? ? ? ? ? ?//创建method对象,方法名 为getMobileCodeInfo?
? ? ? ? ? ? ?OMElement method = factory.createOMElement("getMobileCodeInfo",namespace);?
? ? ? ? ? ? ?OMElement mobileCode = factory.createOMElement("mobileCode",namespace);//方法参数
? ? ? ? ? ? ?OMElement userID = factory.createOMElement("userID",255);">? ? ? ? ? ??
? ? ? ? ? ? ?//封装参数
? ? ? ? ? ? ?mobileCode.addChild(factory.createOMText(mobileCode,"13713718181"));//设定参数的值
? ? ? ? ? ? ?method.addChild(mobileCode); ? ? ? ? ? ?
? ? ? ? ? ? ?userID.addChild(factory.createOMText(userID,""));//设定参数的值
? ? ? ? ? ? ?method.addChild(userID);
? ? ? ? ? ? ?//请求参数设置
? ? ? ? ? ? ?ServiceClient sender = new ServiceClient();
? ? ? ? ? ? ?Options options = new Options();?
? ? ? ? ? ? ?options.setAction("http://WebXml.com.cn/getMobileCodeInfo"); ?
? ? ? ? ? ? ?options.setTo(endpointReference);?
? ? ? ? ? ? ?sender.setOptions(options);?
? ? ? ? ? ? ?OMElement result = sender.sendReceive(method);
? ? ? ? ? ? ?System.out.println(result.getFirstElement().getText());
? ? ? ? ?}?
? ? ? ? ?catch (AxisFault ex)?
? ? ? ? ? ? ?ex.printStackTrace();?
? ? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读