SUDS 生成的 XML 不正确 [英] Incorrect XML produced by SUDS
问题描述
我正在尝试使用 SUDS 和 Python 与 SOAP 网络服务对话.在学习 Python(是的,我是新来的)并研究如何使用 SUDS 之后,我遇到了一个问题.
I am trying to talk to a SOAP web service using SUDS and Python. After lots of messing around learning Python (yes I am new to this) and working out how to use SUDS I have come across a problem.
根据 suds,我正在调用的 Web 方法的签名是
The signature of the web method I am calling, according to suds, is
(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 包如下所示
So I use SUDS to create the classes that I want and send it to the method. However I get an error. So I turned logging on and I can see that the XML that is being sent is not correct which is causing a deserialize error. The SOAP package looks like the following
<?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>
如你所见,有一个'分类事件代码'元素周围所有其他元素,这不应该在那里.如果我将此 xml 剪切并粘贴到 SOAPUI 中,首先删除此元素,然后将其直接发布到 Web 服务,则它会成功运行.
As you can see there is a 'ClassificationEventCode' element around all the other elements, this should not be there. If I cut and paste this xml into SOAPUI and first remove this element and then post it directly to the web service it works successfully.
这是我用来拨打电话的代码
Here is the code I am using to make the call
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.
Does anyone have any ideas why this is happening? I guess SUDS thinks that it should be there based on the WSDL.
谢谢.
推荐答案
我 遇到了完全相同的问题.我的 SOAP 请求中的参数序列被包装在一个与第一个参数同名的元素中.例如
I was getting exactly the same problem. The sequence of parameters in my SOAP request is being wrapped in an element with the same name as the first parameter. e.g.
....
<ns0:Body>
<ns1:CreationReq>
<ReqType>
<ReqType>1</ReqType>
<Title>Mr</Title>
....
</ReqType>
</ns1:CreationReq>
</ns0:Body>
....
我已经检查了 WSDL 以确保它没有问题.
I've checked the WSDL over to make sure there is no problem with it.
问题似乎是因为我使用 client.factory.create 方法创建了一个 CreationReq 对象.通过打印来检查客户端表明我正在调用的方法没有将该对象作为参数.相反,它需要一个命名参数列表.
The problem it seems is because I created a CreationReq object using the client.factory.create method. Checking the client by printing it shows that the method I am calling does not take that object as a parameter. Rather it takes a list of named args.
所以我的代码是:
req = client.factory.create('CreationReq')
req.ReqType = 1
req.Title = 'Mr'
resp = client.service.Create(req)
现在是:
req = {}
req['ReqType'] = 1
req['Title'] = 'Mr'
resp = client.service.Create(**req)
这篇关于SUDS 生成的 XML 不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!