Web Service系列之常见问题
来源:互联网 发布:电缆分层算法 编辑:程序博客网 时间:2024/06/05 02:30
原文链接: Web Service系列之常见问题
问题: Server raised fault: ‘org.xml.sax.SAXException: No deserializer for {http://www.w3.org/2001/XMLSchema}anyType’
CSDN网友回复:
原因就是服务器端将对象序列化为SOAP消息, 到了客户端后进行反序列化, 这个时候在SOAP消息中的某个元素是anyType
类型, 但是和客户端在命名空间中的注册属性无法匹配, 导致不能反序列化, 大部分是命名空间的问题
stackoverflow网友回复:
http://stackoverflow.com/questions/13593950/suds-write-request-missing-datatype
I managed to solve it, using the answer from Adding xsi:type and envelope namespace when using SUDS ( http://stackoverflow.com/a/10977734/696768 )
I am not sure this is the only possible solution, and to me it seems more of a hack than anything else, however it will work fine for my current scenario.
The solution i used, is making a plugin for the client, looking for the particular element that i need to be xsi:type=”xsd:int”, then adding these attributes to those elements.
The code i ended up using for reference (from the aforementioned stackoverflow question with minor adjustments):
from suds.plugin import MessagePluginfrom suds.sax.attribute import Attributeclass SoapFixer(MessagePlugin): def marshalled(self, context): # Alter the envelope so that the xsd namespace is allowed context.envelope.nsprefixes['xsd'] = 'http://www.w3.org/2001/XMLSchema' # Go through every node in the document and apply the fix function to patch up incompatible XML. context.envelope.walk(self.fix_any_type_string) def fix_any_type_string(self, element): """Used as a filter function with walk in order to fix errors. If the element has a certain name, give it a xsi:type=xsd:int. Note that the nsprefix xsd must also be added in to make this work.""" # Fix elements which have these names fix_names = ['Value', 'anotherelementname'] if element.name in fix_names: element.attributes.append(Attribute('xsi:type', 'xsd:int'))plugin=SoapFixer()
Then I added plugins=[plugin] to the client ctor.
Example:
client = suds.client.Client("http://127.0.0.1:8099/TagValueWriteService?wsdl",plugins=[plugin])
补充:
https://wiki.python.org/moin/WebServices
Web Service: JSON-RPC JSON-WSP SOAP SOAPjr XML-RPC XMPP
- Web Service系列之常见问题
- Web Service系列之实例之spyne
- Web Service系列之数组参数
- OSGI系列 Web-Service
- Web Service系列之实例之JAX-WS
- 构建安全的Xml Web Service系列之SSL篇
- 入学习Web Service系列之异步开发模式
- 构建安全的Xml Web Service系列之SSL篇
- 构建安全的Xml Web Service系列之SSL篇
- Web service之我见
- Web Service之XFire
- Web Service之服务
- Web Service之介绍
- EJB之Web Service
- Web Service 之 SOAP
- Web Service 之SOAP
- SharePoint Web Service系列:编写自定义SharePoint Web Services之二
- SharePoint Web Service系列:编写自定义SharePoint Web Services之二
- java数据类型的范围
- 学习记录 蝙蝠算法
- SSL 2299——护卫队
- python3.5.2中pycharm中pip install xgboost出现No files/directories in...
- 关于elasticsearch的问题解决记录
- Web Service系列之常见问题
- 2_1最近邻算法kNN(k_nearest_neighbor)——classify0_2_1
- 国外程序员整理的机器学习资源大全
- 科普: 知道阿里、苹果、腾讯等牛逼互联网公司名字的由来吗?
- 从头开发git-1
- 购物车
- Unity面试题170420
- 小心那些灾星
- 强大的矩阵奇异值分解(SVD)及其应用