XML SOAP POST error, what am I doing wrong?

So, I'm trying to make an API call through XML SOAP POST, which I get: "The reference to the object is not installed in the instance of the object"

site = 'https://webservices.autotask.net/atservices/1.5/atws.asmx'
data = """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <queryxml>
      <entity>contact</entity>
        <query>
          <field>firstname<expression op="equals">George</expression>
          </field>
        </query>
    </queryxml>
  </soap:Body>
</soap:Envelope>"""

headers = {
    'Content-Type': 'application/soap+xml; charset=utf-8',
    'Host': 'webservices.autotask.net',
    'Content-Type': 'text/xml; charset=utf-8',
    'Content-Length': len(data),
    'SOAPAction': "http://autotask.net/ATWS/v1_5/query"
    } 
site = 'https://webservices.autotask.net/atservices/1.5/atws.asmx'
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='webservices.autotask.net',
                          uri=site,
                          user='user,
                          passwd='pw')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
page = urllib2.urlopen(site)
print(data)
req = urllib2.Request(site, data, headers)
response = urllib2.urlopen(req)
the_page = response.read()
print(the_page)

Auth works, and I made successful calls with this code, the only thing that is different now from XML SOAP POST. I will try to drink.

The error is only for tracing only on the server:

Print the submitted XML-SOAP POST:

<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <queryxml> <entity>contact</entity> <query> <field>firstname<expression op="equals">George</expression> </field> </query> </queryxml> </soap:Body> </soap:Envelope>

Answer:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><queryResponse xmlns="http://autotask.net/ATWS/v1_5/"><queryResult><ReturnCode>-1</ReturnCode><EntityResults /><EntityResultType /><Errors><ATWSError><Message>Object reference not set to an instance of an object.</Message></ATWSError><ATWSError><Message>Error reading in Query XML.</Message></ATWSError></Errors><EntityReturnInfoResults /></queryResult></queryResponse></soap:Body></soap:Envelope>

Any ideas?

George

+3
source share
3 answers

Autotask has an ancient API on IIS 6 ... to work with micropackstack you must avoid the XML that you click there as CDATA. Here is what worked for me like soap, inside

<ins0:query> 

tags:

<ins0:sXML>
<![CDATA[<queryxml>
<entity>contact</entity>
<query>
<field>phone<expression op='equals'>#{phone}</expression></field>
</query>
</queryxml>]]>
</ins0:sXML>
+6
source

, - webservicex.net:

import suds
url = 'http://www.webservicex.net/stockquote.asmx?WSDL'
client = suds.client.Client(url=url)
print client.service.GetQuote('IBM')

<StockQuotes>
  <Stock>
     <Symbol>IBM</Symbol>
     <Last>159.93</Last><Date>3/7/2011</Date><Time>4:00pm</Time>
     <Change>-1.90</Change><Open>161.60</Open><High>162.98</High>
     <Low>158.85</Low><Volume>5318064</Volume>
     <MktCap>195.0B</MktCap><PreviousClose>161.83</PreviousClose>
     <PercentageChange>-1.17%</PercentageChange>
     <AnnRange>116.00 - 166.25</AnnRange>
     <Earns>11.52</Earns><P-E>14.05</P-E>
     <Name>International Bus</Name>
  </Stock>
</StockQuotes>

HTTP, :

client = suds.client.Client(url=url, username='user', password='pw')

!

+2

, , API "", . , , , XML .

, , XML.

Eskim0 , , , , , . "sXML" SOAP.

(perl, python php, , ) , somexxxml sXML ify. , , .

So, for example, in perl you would do this:

$soap->query(SOAP::Data->value($query)->name('sXML'))

which would issue the sXML version of the $ query string to the query method at the soap endpoint.

0
source

All Articles