java webservice asmx_WebService-asmx后缀接口调用

简述:.asmx是webservice服务程序的后缀名,ASP.NET 使用.asmx 文件来对Web Services的支持。.asmx 文件和.aspx文件一样都属于文本文件。它包含在.aspx文件之中,成为ASP.NET应用程序的一部分。

废话不多说上代码

POM引用

commons-discovery

commons-discovery

0.2

webService接口调用,并解析

@Override

public List> selectStoreList(String FTY_CODE_, String DEPT_CODE_)throwsException {

List> storeItemList_ = new ArrayList<>();

//获取webservice接口地址

String endpoint = "http://10.18.26.71/WebService_SB/WS_EquipService.asmx";

//获取域名地址,server定义的

String soapaction = "http://tempuri.org/";

//调用的方法名

String method = "getStoreList";

//创建一个服务(service)调用(call)

org.apache.axis.client.Service service = neworg.apache.axis.client.Service();

//创建一个服务(service)调用(call)

Call call = (Call) service.createCall();//通过service创建call对象

//设置service所在URL

call.setTargetEndpointAddress(endpoint);

call.setOperationName(newQName(soapaction, method));

//设置参数及类型,与接口参数对应

call.addParameter(new QName(soapaction, "plant"),

org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

call.addParameter(new QName(soapaction, "depart"),

org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

call.setUseSOAPAction(true);

call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回参数的类型

call.setSOAPActionURI(soapaction + method); //这个也要注意 就是要加上要调用的方法getStoreList,不然也会报错

//invoke调用方法并传递参数,获取XML

String xmlStr = (String) call.invoke(newObject[]{FTY_CODE_, DEPT_CODE_});

if (xmlStr != null) {

StoreItemList storeItemList = BaseUtils.xmlToBean(xmlStr, StoreItemList.class);

MapstoreItem_;

for(StoreItem item : storeItemList.getStoreItemList()) {

storeItem_ = new HashMap();

storeItem_.put("STORE_ID_", item.getStoreId());

storeItem_.put("STORE_DESC_", item.getStoreDesc());

storeItemList_.add(storeItem_);

}

}

returnstoreItemList_;

}

以上是调用,如果有兴趣请往下看,具体实现的栗子

首先调用webServcie返回的xml数据样式要知道:

234

金矿厂机关作业区备件库房

233

金矿厂机关作业区材料库房

235

金矿厂机关作业区材料1库房

236

金矿厂机关作业区虚拟库房

根据返回的xml文件,创建自己的StoreItemList实体类(解析xml用)

packageorg.building.er.bean;importjavax.xml.bind.annotation.XmlAccessType;importjavax.xml.bind.annotation.XmlAccessorType;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;importjava.io.Serializable;importjava.util.List;/***@authordimo

* @date 2020/6/28*/@XmlRootElement(name= "items")

@XmlAccessorType(XmlAccessType.FIELD)public class StoreItemList implementsSerializable {private static final long serialVersionUID = 1L;

@XmlElement(name= "item")private ListstoreItemList;public StoreItemList(ListstoreItemList) {this.storeItemList =storeItemList;

}public ListgetStoreItemList() {returnstoreItemList;

}public void setItemList(ListstoreItemList) {this.storeItemList =storeItemList;

}

}

根据返回的xml文件,创建自己的创建StoreItem 实体类(解析xml用)

packageorg.building.er.bean;import javax.xml.bind.annotation.*;importjava.io.Serializable;/***@authordimo

* @date 2020/6/28*/@XmlRootElement(name="item")

@XmlType(propOrder= {"store_id", "store_desc"})

@XmlAccessorType(XmlAccessType.FIELD)public class StoreItem implementsSerializable {private static final long serialVersionUID = 1L;privateString store_id;privateString store_desc;publicStoreItem() {

}publicString getStoreId() {returnstore_id;

}public voidsetStoreId(String store_id) {this.store_id =store_id;

}publicString getStoreDesc() {returnstore_desc;

}public voidsetStoreDesc(String store_desc) {this.store_desc =store_desc;

}

}

说明:这里创建两个实体类的原因,返回的xml文件套了两层(即和),其解析xml要的是和的值,解析的时候转换成实体类要一层一层;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值