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

xfire客户端代码,对于复杂类型的调用

发布时间:2020-12-17 01:18:40 所属栏目:安全 来源:网络整理
导读:复杂的类型我们这里就是像Map,List等的集合类型,或Person这种我们自己定义的Pojo类。 这些类型在我们的web服务端进行了相应的使用。 例如在和别的公司进行调试的时候,他们用的xfire做的webservice的服务端,好了后会给你个wsdl 在上面的的文章我写了,可

复杂的类型我们这里就是像Map,List等的集合类型,或Person这种我们自己定义的Pojo类。

这些类型在我们的web服务端进行了相应的使用。

例如在和别的公司进行调试的时候,他们用的xfire做的webservice的服务端,好了后会给你个wsdl

在上面的的文章我写了,可以利用ant自动生成一堆代码。

?

1 自定义的Person类,在客户端调用

?

// Person p = new Person();

// p.setAge(20);

// //注意namespace要和wsdl中的一致,否则不能辨认出来

// p.setName(new JAXBElement<String>(new

// QName("http://pojo","name"),String.class,"lambert"));

?

?

自动生成的代码会是如下的样子:Person.java

?

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "Person",propOrder = {

?? ?"age",

?? ?"name"

})

public class Person {

?

?? ?protected Integer age;

?? ?@XmlElementRef(name = "name",namespace = "http://pojo",type = JAXBElement.class)

?? ?protected JAXBElement<String> name;

?

?? ?/**

?? ? * Gets the value of the age property.

?? ? *?

?? ? * @return

?? ? * ? ? possible object is

?? ? * ? ? {@link Integer }

?? ? * ? ??

?? ? */

?? ?public Integer getAge() {

?? ? ? ?return age;

?? ?}

?

?? ?/**

?? ? * Sets the value of the age property.

?? ? *?

?? ? * @param value

?? ? * ? ? allowed object is

?? ? * ? ? {@link Integer }

?? ? * ? ??

?? ? */

?? ?public void setAge(Integer value) {

?? ? ? ?this.age = value;

?? ?}

?

?? ?/**

?? ? * Gets the value of the name property.

?? ? *?

?? ? * @return

?? ? * ? ? possible object is

?? ? * ? ? {@link JAXBElement }{@code <}{@link String }{@code >}

?? ? * ? ??

?? ? */

?? ?public JAXBElement<String> getName() {

?? ? ? ?return name;

?? ?}

?

?? ?/**

?? ? * Sets the value of the name property.

?? ? *?

?? ? * @param value

?? ? * ? ? allowed object is

?? ? * ? ? {@link JAXBElement }{@code <}{@link String }{@code >}

?? ? * ? ??

?? ? */

?? ?public void setName(JAXBElement<String> value) {

?? ? ? ?this.name = ((JAXBElement<String> ) value);

?? ?}

?

}

?

?

2 Map类型的。

??这时候会自动生成一个AnyType2AnyTypeMap.java的类,接口中的调用参数也是AnyType2AnyTypeMap这种类型的。

??我们要制造了.

??ObjectFactory fac = new ObjectFactory(); ?//在AnyType2AnyTypeMap的同个包中就有

??AnyType2AnyTypeMap at2am = fac.createAnyType2AnyTypeMap();

??List<AnyType2AnyTypeMap.Entry> list = at2am.getEntry();

?//对于传进来的map

??Map map = new HashMap();

??map.put("name","rose");

??map.put("age","23");

??Iterator<Map.Entry<String,String>> it = map.entrySet().iterator();

??while(it.hasNext()){

??Map.Entry<String,String> entry = it.next();

??AnyType2AnyTypeMap.Entry ey = fac.createAnyType2AnyTypeMapEntry();

??ey.setKey(entry.getKey());

??ey.setValue(entry.getValue());

??list.add(ey);

}

spt.printMap(at2am); ?//接口的调用

?

3 List类型

?? 同2 中的差不多也是列用ObjectFactory

?

ArrayOfString bookNames = fac.createArrayOfString();
??List<String> bookNameList = bookNames.getString();
??bookNameList.add("《社会心理学》");
??bookNameList.add("《心理学与生活》");

.......//调用

(编辑:李大同)

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

    推荐文章
      热点阅读