wsdl中,soapenc:string和soapenc:int是什么类型? 博客分类: 开源框架_Axis2
程序员文章站
2024-03-20 19:17:04
...
先看看下面的wsdl片段:
看到没,里面有很多soapenc:string和soapenc:int类型的元素,开始没太注意。后来发现用wsdl2java生成的代码,都不是java.lang.String类型或int类型的。axis2对其加了一层壳。
比如上面的userId元素,如何在服务端获取呢?
org.apache.axis2.databinding.types.soapencoding.String UserId0 = req.getUserId();
String UserId = UserId0 != null ? UserId0.getString() : null;
log.debug("handle UserId=" + UserId);
又比如上面的updateType元素,在服务端这样获取:
org.apache.axis2.databinding.types.soapencoding._int UpdateType0 = req.getUpdateType();
Integer UpdateType = UpdateType0 != null ? UpdateType0.get_int() : null;
log.debug("handle UpdateType=" + UpdateType);
像这样的类型,在设置的时候也需要手动加壳,举两个例子:
static org.apache.axis2.databinding.types.soapencoding.String toSoapString(String str) {
org.apache.axis2.databinding.types.soapencoding.String enc = new org.apache.axis2.databinding.types.soapencoding.String();
enc.setString(str);
return enc;
}
static org.apache.axis2.databinding.types.soapencoding._int toSoapInt(int val) {
org.apache.axis2.databinding.types.soapencoding._int enc = new org.apache.axis2.databinding.types.soapencoding._int();
enc.set_int(val);
return enc;
}
使用起来是这样的:
rsp.setUserId(toSoapString("1234"));
rsp.setUpdateType(toSoapInt(1234));
<complexType name="OrderRelationUpdateNotifyRequest"> <sequence> <element name="recordSequenceId" nillable="true" type="soapenc:string"/> <element name="userIdType" nillable="true" type="soapenc:int"/> <element name="userId" nillable="true" type="soapenc:string"/> <element name="serviceType" nillable="true" type="soapenc:string"/> <element name="spId" nillable="true" type="soapenc:string"/> <element name="productId" nillable="true" type="soapenc:string"/> <element name="updateType" nillable="true" type="soapenc:int"/> <element name="updateTime" nillable="true" type="soapenc:string"/> <element name="updateDesc" nillable="true" type="soapenc:string"/> <element name="linkId" nillable="true" type="soapenc:string"/> <element name="content" nillable="true" type="soapenc:string"/> <element name="effectiveDate" nillable="true" type="soapenc:string"/> <element name="expireDate" nillable="true" type="soapenc:string"/> <element name="time_stamp" nillable="true" type="soapenc:string"/> <element name="encodeStr" nillable="true" type="soapenc:string"/> </sequence> </complexType>
看到没,里面有很多soapenc:string和soapenc:int类型的元素,开始没太注意。后来发现用wsdl2java生成的代码,都不是java.lang.String类型或int类型的。axis2对其加了一层壳。
比如上面的userId元素,如何在服务端获取呢?
org.apache.axis2.databinding.types.soapencoding.String UserId0 = req.getUserId();
String UserId = UserId0 != null ? UserId0.getString() : null;
log.debug("handle UserId=" + UserId);
又比如上面的updateType元素,在服务端这样获取:
org.apache.axis2.databinding.types.soapencoding._int UpdateType0 = req.getUpdateType();
Integer UpdateType = UpdateType0 != null ? UpdateType0.get_int() : null;
log.debug("handle UpdateType=" + UpdateType);
像这样的类型,在设置的时候也需要手动加壳,举两个例子:
static org.apache.axis2.databinding.types.soapencoding.String toSoapString(String str) {
org.apache.axis2.databinding.types.soapencoding.String enc = new org.apache.axis2.databinding.types.soapencoding.String();
enc.setString(str);
return enc;
}
static org.apache.axis2.databinding.types.soapencoding._int toSoapInt(int val) {
org.apache.axis2.databinding.types.soapencoding._int enc = new org.apache.axis2.databinding.types.soapencoding._int();
enc.set_int(val);
return enc;
}
使用起来是这样的:
rsp.setUserId(toSoapString("1234"));
rsp.setUpdateType(toSoapInt(1234));