我正在尝试使用 SUDS 和 Python 与 SOAP Web 服务通信。经过大量学习 Python(是的,我是新手)并研究如何使用 SUDS 之后,我遇到了一个问题。
根据 suds,我正在调用的 Web 方法的签名是
(FWTCaseCreate){
ClassificationEventCode = None
Priority = None
Title = None
Description = None
Queue = None
DueDate = None
AssociatedObject =
(FWTObjectBriefDetails){
ObjectID =
(FWTObjectID){
ObjectType = None
ObjectReference[] = <empty>
}
ObjectDescription = None
Details = None
Category = None
}
Form =
(FWTCaseForm){
FormField[] = <empty>
FormName = None
FormKey = None
}
Internal = None
InteractionID = None
XCoord = None
YCoord = None
}
所以我使用 SUDS 创建我想要的类并将其发送到方法。但是我得到一个错误。所以我打开了登录,我可以看到正在发送的 XML 不正确,这导致了反序列化错误。SOAP 包如下所示
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://www.CRM.com/wsdl/FLTypes" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security>
<wsse:BinarySecurityToken>eaadf1ddff99a8</wsse:BinarySecurityToken>
</wsse:Security>
</SOAP-ENV:Header>
<ns1:Body>
<ns0:FWTCaseCreate>
<ClassificationEventCode>
<ClassificationEventCode>2000023</ClassificationEventCode>
<Priority>1</Priority>
<Title>testing</Title>
<Description>testing</Description>
<Queue/>
<Internal>True</Internal>
<XCoord>356570</XCoord>
<YCoord>168708</YCoord>
</ClassificationEventCode>
</ns0:FWTCaseCreate>
</ns1:Body>
如您所见,所有其他元素周围都有一个“ClassificationEventCode”元素,这不应该存在。如果我将此 xml 剪切并粘贴到 SOAPUI 中并首先删除此元素,然后将其直接发布到 Web 服务,它会成功运行。
这是我用来拨打电话的代码
client = Client(url)
#Add a header for the security
ssnns = ('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd')
ssn = Element('BinarySecurityToken', ns=ssnns).setText(binaryKey)
ssn1 = Element('Security',ns=ssnns)
ssn1.append(ssn)
client.set_options(soapheaders=ssn1)
newCase = client.factory.create('ns1:FWTCaseCreate')
classEventCode = client.factory.create('ns1:FWTEventCode')
classEventCode.value = 2000023
newCase.ClassificationEventCode = classEventCode
newCase.Priority = 1
#optional
newCase.AssociatedObject = None
#optional
newCase.Form = None
#optional
newCase.Internal = None
#optional
newCase.InteractionID = None
#optional
newCase.DueDate = None
#optional
newCase.Queue = None
newCase.Title = 'Title'
newCase.Description = 'description'
newCase.XCoord = '356570'
newCase.YCoord = '168708'
caseID = client.service.createCase(newCase)
有谁知道为什么会这样?我猜 SUDS 认为它应该基于 WSDL 存在。
谢谢。