简体   繁体   English

如何通过SOAPPy(python)或SUDS发送嵌套的SOAP请求

[英]How to send nested SOAP request via SOAPPy (python) or SUDS

I'm trying to generate soap request simliar to this : 我正在尝试为此生成soap请求simliar:

I've been able to access the server via soappy , but i didn't find a good example to to pass nest xml parameter to GetStopMonitoringService 我已经能够通过soappy访问服务器,但我没有找到一个很好的例子来将nest xml参数传递给GetStopMonitoringService

I would be if someone can provide some info/like to an example . 如果有人可以提供一些信息/喜欢一个例子,我会的。

thanks . 谢谢 。

A sample soap request i need to gerenate via python : 我需要通过python进行gerenate的示例soap请求:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:acsb="http://www.ifopt.org.uk/acsb" xmlns:datex2="http://datex2.eu/schema/1_0/1_0" xmlns:ifopt="http://www.ifopt.org.uk/ifopt" xmlns:siri="http://www.siri.org.uk/siri" xmlns:siriWS="http://new.webservice.namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="./siri">
        <SOAP-ENV:Header />
        <SOAP-ENV:Body>
            <siriWS:GetStopMonitoringService>
                <Request xsi:type="siri:ServiceRequestStructure">
                    <siri:RequestTimestamp>2012-10-31T09:39:39.480+02:00</siri:RequestTimestamp>
                    <siri:RequestorRef xsi:type="siri:ParticipantRefStructure">KLM12345</siri:RequestorRef>
                    <siri:MessageIdentifier xsi:type="siri:MessageQualifierStructure">0100700:1351669188:4684</siri:MessageIdentifier>
                    <siri:StopMonitoringRequest version="IL2.6" xsi:type="siri:StopMonitoringRequestStructure">
                        <siri:RequestTimestamp>2012-10-31T09:39:39.480+02:00</siri:RequestTimestamp>
                        <siri:MessageIdentifier xsi:type="siri:MessageQualifierStructure">0</siri:MessageIdentifier>
                        <siri:PreviewInterval>PT1H</siri:PreviewInterval>
                        <siri:MonitoringRef xsi:type="siri:MonitoringRefStructure">39795</siri:MonitoringRef>
                        <siri:MaximumStopVisits>100</siri:MaximumStopVisits>
                    </siri:StopMonitoringRequest>
                </Request>
            </siriWS:GetStopMonitoringService>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

I use this python code : 我用这个python代码:

    #!/usr/bin/python
    from  SOAPpy  import SOAPProxy
    import httplib
    httplib.HTTPConnection.debuglevel = 1
    soapaction='http://siri.motrealtime.co.il:8081/Siri/SiriServices/GetStopMonitoringService'
    namespace='http://www.ifopt.org.uk/ifopt'
    server = SOAPProxy('http://siri.motrealtime.co.il:8081/Siri/SiriServices',soapaction=soapaction,namespace=namespace)
    Request =  { 
    'RequestTimestamp':"2014-02-04T09:39:39.480+02:00",
    'RequestorRef':"AG566778",
    'MessageIdentifier':"0100700:1351669188:4684",
    'StopMonitoringRequest': 
        {'version':"IL2.6",
        'RequestTimestamp' :"2014-02-04T09:39:39.480+02:00",
        'MessageIdentifier':0,
        'PreviewInterval':"PT1H",
        'MonitoringRefStructure':21705,
        'MaximumStopVisits':100}
    }

    server.soapproxy.config.dumpSOAPOut = 1     
    server.soapproxy.config.dumpSOAPIn = 1
    print  server.GetStopMonitoringService(Request = Request)

but it still doesn't work 但它仍然无效

I read the source code to figure this out. 我阅读了源代码来解决这个问题。 I recommend doing the same when you are stuck! 当你被卡住时我建议做同样的事情!

The essential answer to your question (for SOAPpy) is that you need to use a "structType" in order to create a nesting. 您的问题(对于SOAPpy)的基本答案是您需要使用“structType”来创建嵌套。 Here's an example code snippet where I add a soap header, and in that header I've nested a "SessionHeader" node, and within that a "sessionId" node. 这是一个示例代码片段,其中我添加了一个soap标头,在该标头中我嵌套了一个“SessionHeader”节点,并在其中嵌套了一个“sessionId”节点。

from SOAPpy import WSDL, Types as soapTypes
....
soapProxy = server.soapProxy._sa( "urn:sessionid" )
soapHeader = soapTypes.headerType()
soapHeader.SessionHeader = soapTypes.structType( None, "SessionHeader" )
soapHeader.SessionHeader.sessionId = soapTypes.stringType( sessionId )
soapProxy = soapProxy._hd( soapHeader )
server.soapproxy = soapProxy

That produces this SOAP (well, the header section of the xml): 这产生了这个SOAP(以及xml的头部分):

<SOAP-ENV:Header>
    <xsd:SessionHeader SOAP-ENC:root="1">
        <sessionId xsi:type="xsd:string">345423534532774</sessionId>
    </xsd:SessionHeader>
</SOAP-ENV:Header>

The same kind of thing could be achieved with the soap body. 肥皂体可以达到同样的效果。

Note that anywhere you see "SessionHeader" or "sessionid" here, that is an arbitrary customization. 请注意,只要您在此处看到“SessionHeader”或“sessionid”,就可以进行任意定制。 Those could have whatever names you want for your own purposes. 那些可以为你自己的目的找到你想要的任何名字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM