Web Service系列之常见问题
2017-04-21 21:52
106 查看
原文链接: 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):
Then I added plugins=[plugin] to the client ctor.
Example:
补充:
https://wiki.python.org/moin/WebServices
Web Service: JSON-RPC JSON-WSP SOAP SOAPjr XML-RPC XMPP
问题: 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 MessagePlugin from suds.sax.attribute import Attribute class 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
相关文章推荐
- MDaemon常见系列问题问答
- NS系列防火墙常见问题总结(有问题的朋友先到这里看看)
- 常见magento问题系列四-----后台的分类页面不正常显示
- 常见的magent问题系列二--Fatal error: Call to a member function toHtml() on a non-object in ../../Layout.php
- 【Qt常见问题】系列02
- 【Qt常见问题】系列01
- 【常见问题】系列01:双击文件夹打开新窗口
- 常见magento的问题系列一--第一次进入后台分类管理 和 Manage Store 界面时 发生的错误
- Timesten系列之三:TimesTen常见问题
- 开源ETL工具kettle系列之常见问题(转载)(
- 指针使用常见问题的解答与求教系列(2)
- JAVA视频教程,学习JAVA常见问题分析-JAVA学习方法系列
- 开源ETL工具kettle系列之常见问题
- 开源ETL工具kettle系列之常见问题
- JBoss5开发web service常见问题
- 深入JVM系列(三)之类加载、类加载器、双亲委派机制与常见问题
- MVC3+EF4.1学习系列(十一)----EF4.1常见的问题解决
- 开源ETL工具kettle系列之常见问题