我使用spyne在服务器端使用python与excel客户端(xmla插件)进行通信来生成web服务,并且我生成肥皂响应与客户端请求匹配时遇到了一些困难, 我要的是这样一个SOAP响应(下根标签模式与 “XSD:” 是指的xmlns:XSD =“http://www.w3.org/2001/XMLSchema在根:肥皂响应中的python xsd
<soap:Envelope xmlns="urn:schemas-microsoft-com:xml-analysis">
<soap:Body>
<DiscoverResponse xmlns="urn:...">
<return>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"
....>
< xsd:schema targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="row" type="row"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="uuid">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="xmlDocument">
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="row">
<xsd:sequence>
<xsd:element sql:field="PropertyName" name="PropertyName" type="xsd:string"/>
<xsd:element sql:field="PropertyDescription" name="PropertyDescription" type="xsd:string" minOccurs="0"/>
<xsd:element sql:field="PropertyType" name="PropertyType" type="xsd:string" minOccurs="0"/>
<xsd:element sql:field="PropertyAccessType" name="PropertyAccessType" type="xsd:string"/>
<xsd:element sql:field="IsRequired" name="IsRequired" type="xsd:boolean" minOccurs="0"/>
<xsd:element sql:field="Value" name="Value" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</root>
</return>
</DiscoverResponse>
</soap:Body>
,我与spyne得到了结果,每次不包含XSD:
<soap11env:Body>
<tns:DiscoverResponse>
<tns:return>
<ns2:root xmlns:ns2="urn:schemas-microsoft-com:xml-analysis:rowset">
<ns3:schema xmlns:ns3="services.models" targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset"/>
</ns2:root>
</tns:return>
</tns:DiscoverResponse>
这里是我的Python代码:
在models.py文件:
class schema(ComplexModel):
targetNamespace = XmlAttribute(Unicode)
__type_name__ = "schema"
class DiscoverResponse(ComplexModel):
__namespace__ = "urn:schemas-microsoft-com:xml-analysis:rowset"
root = Array(schema.customize(max_occurs='unbounded'))
in xmla.py file:
class xmla_provider(ServiceBase):
@rpc(Unicode,
Restrictionlist,
Propertielist,
_returns=[DiscoverResponse],
_out_variable_names=["return"])
def Discover(ctx, RequestType, Restrictions, Properties):
response = DiscoverResponse()
response.root = schema(targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset"),
return response
来解决这个问题我想补充 __ __命名空间= “http://www.w3.org/2001/XMLSchema” 在类架构 和我得到这个问题
如果child_ns!=在self.imports [NS] NS,而不是child_ns和\ KeyError异常:“http://www.w3.org/2001/XMLSchema”
想到的和这不是一个好的解决方案另一种解决方案,是力通过返回所有
SOAP响应到根 attribut为Unicode
这里是代码:在xmla.py
response.root = "\n < xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='urn:schemas-microsoft-com:xml-analysis:rowset' ....
在模型
。PY
class DiscoverResponse(ComplexModel):
__namespace__ = "urn:schemas-microsoft-com:xml-analysis:rowset"
root = Unicode
和我得到这个输出
DEBUG:spyne.protocol.xml:Response <soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="urn:schemas-microsoft-com:xml-analysis">
<soap11env:Body>
<tns:DiscoverResponse>
<tns:return>
<ns0:root xmlns:ns0="urn:schemas-microsoft-com:xml-analysis:rowset">
< xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns='urn:schemas-microsoft-com:xml-analysis:rowset'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:sql='urn:schemas-microsoft-com:xml-sql'
....
/xsd:schema
</ns0:root>
</tns:return>
</tns:DiscoverResponse>
所有<>字符被替换为 “& LT;”和“& gt”; (正如我所说这不是一个好的解决方案,通常我必须解决名称空间的问题)
请任何建议来解决问题或在最坏的情况下,在Python中的任何建议,样的反应
我感到困惑,每个人都为晚问Spyne问题都没有在它Spyne代码的单个斑点。我需要看代码!错误!来吧,帮我帮你! –
你设置了_returns = AnyXml吗?你如何产生回应? –
抱歉不清楚,我更新了我的问题@BurakArslan –