在Web Service中定义了复杂类型之后,Axis2会生成对应的类对象。这些类都是可以序列化的。
可以把这些类的实例和字符串之间做相互转化。
// 对象转换成字符串
StringWriter stringWriter = new StringWriter();
XMLStreamWriter xmlStreamWriter = StAXUtils
.createXMLStreamWriter(stringWriter);
MTOMAwareXMLStreamWriter mtomAwareXMLStreamWriter = new MTOMAwareXMLSerializer(
xmlStreamWriter);
userCredentialsType.serialize(new QName(
"http://newautovideo.com/siteengine/ws/types", "ns1"),
OMAbstractFactory.getSOAP11Factory(), mtomAwareXMLStreamWriter);
xmlStreamWriter.flush();
xmlStreamWriter.close();
String omElementString = stringWriter.toString();
System.out.println("OM String ==> " + omElementString);
// 字符串转换成对象
XMLStreamReader xmlReader = StAXUtils
.createXMLStreamReader(new ByteArrayInputStream(omElementString
.getBytes()));
UserCredentialsType result = UserCredentialsType.Factory
.parse(xmlReader);
System.out.println("OM Object==> " + result.getUserID());
posted on 2009-03-18 21:24
夜露死苦 阅读(1459)
评论(0) 编辑 收藏