Programming SOAP


This is a short tutorial that is dedicated to help PHP programmers who get in trouble connecting a SOAP-service using the native php5 soap functions.

This part describes how to check a SOAP-call on a command line. If you have trouble connecting a SOAP-Service you should do this first, to ensure you have created a valid SOAP-Request.

To check if your soap-request is well-formed, put it into a file e.g. soaptest.xml and check it with xmllint
xmllint soaptest.xml

If everything is ok, the program will output the file content, otherwise it will throw an error message.

When there appears no error, the second step is to check if the soap-request will produce a response without errors. To check this out we can use the curl program.
Sometimes you have to send several requests to the soap-server. To simplify the requests we create a curl config file (e.g. soapheader.txt) with the appropriate parameters:

header = "Content-Type: text/xml; charset=utf-8"
header = "SOAPAction: urn:<uri to soap-function>"
data = "@soaptest.xml"
url = "<url to soap-service>"

Do the test request:

curl -K soapheader.txt

to format the output we can use xmllint again

curl -K soapheader.txt | xmllint --format -

If you are lucky you will receive a soap-response and if you are very lucky the xml-response is what you expected.
Otherwise there appears no response or rather no output, this occurs when your request produces a server error. To have a look to the server response you can dump the header information to a file (e.g. header.txt):

curl -K soapheader.txt -D header.txt

With this information you should be able to solve your problems 😉

Dieser Beitrag wurde unter soap veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar