您的位置:首页 > 其它

调用webservices服务一个异常处理:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in someth

2009-07-15 11:09 651 查看
今天调用一个webservices服务抛出一个异常:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in someth ing it was trying to deserialize.

网上找资料花了一天才搞定.

调用webservices代码:

GetSubscriptionReq input = new GetSubscriptionReq();
GetSubscriptionRsp output = null;
Service service = new Service();
Call call = (Call)service.createCall();
call.setTimeout(new Integer(20000));
org.apache.axis.description.OperationDesc oper;
org.apache.axis.description.ParameterDesc param;
oper = new org.apache.axis.description.OperationDesc();
oper.setName("getSubscription");
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://portalEngine.ismp.chinatelecom.com", "getSubscriptionReq"),
org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://req.portalEngine.ismp.chinatelecom.com", "GetSubscriptionReq"),
GetSubscriptionReq.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName("http://rsp.portalEngine.ismp.chinatelecom.com", "GetSubscriptionRsp"));
oper.setReturnClass(GetSubscriptionRsp.class);
oper.setReturnQName(new javax.xml.namespace.QName("http://portalEngine.ismp.chinatelecom.com", "getSubscriptionRsp"));
oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
call.setOperation(oper);
call.setOperationName("getSubscription");
call.setTargetEndpointAddress("http://"+service_addr+"/PortalEngineService");

try{
output = (GetSubscriptionRsp)call.invoke(new Object[]{input});//调用webservices服务
}catch(Exception e)
{
throw new ServantException("core_invoke_webservices_failure",e.getMessage());
}


如果services返回的结果GetSubscriptionRsp类对象里面没有关联另外一个SubInfo类对象. 就不会报这样的异常. 服务返回结果的GetSubscriptionRsp类对象里关联另外一个SubInfo类对象25行就抛出这个异常. 异常的意思看似返回的结果中有个子元素不能反序列化. 估计是不能反序列为SubInfo. 到网上查了N久找到处理的方法, 国内一些留言的没找到相关解决办法. 参考了国外高人的留言,一个一个字的慢慢看(看来英语还是很重要.) 找到了处理方法:
增加了几行代码:
TypeMappingRegistry registry = service.getTypeMappingRegistry();
TypeMapping mapping = registry.createTypeMapping();
registerBeanMapping(mapping, GetSubscriptionReq.class,new javax.xml.namespace. QName("http://req.portalEngine.ismp.chinatelecom.com", "GetSubscriptionReq"));
registerBeanMapping(mapping, GetSubscriptionRsp.class,new javax.xml.namespace. QName("http://rsp.portalEngine.ismp.chinatelecom.com", "GetSubscriptionRsp"));
registerBeanMapping(mapping, SubInfo.class,new javax.xml.namespace. QName("http://rsp.portalEngine.ismp.chinatelecom.com", "SubInfo"));
registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping);
protected void registerBeanMapping(TypeMapping mapping, Class type,
javax.xml.namespace.QName qname) {
mapping.register(type, qname, new BeanSerializerFactory(type, qname),
new BeanDeserializerFactory(type, qname));
}


异常就再也没有抛出来了, 总算送了一口气. 虽然问题解决了. 但是还是不知道什么原因. 为什么要加这几行代码? 请各位高人指点.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐