Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to learn SOAP? [closed]

I've created a web application with a mapping component. I want to use another geocoding service other than google, but all the ones I've found use SOAP to communicate with the website. I've never used soap before. Does anyone know of any good resources to help me figure this out? I"m using PHP to integrate to build the web app.

Edit: I need to use Soap for geocoding right now... so if you know any good services for that too, that'd be great. Thanks!

EDIT Again: I basically need to learn soap so I can interact with http://www.nn4d.com/site/global/build/web_services/geocoding_reversegeocoding/map24geocoder51service/map24geocoder51service.jsp

like image 566
Bill Avatar asked Nov 16 '10 16:11

Bill


1 Answers

Learning SOAP on its own requires you to learn XML and lots of SOAP-specific stuff.

However, you've tagged your question PHP, so I assume what you're actually asking is to learn how to use a SOAP web service through PHP. This is different to learning SOAP itself because PHP (like most other languages) abstracts the messy XML bits of SOAP and turns it into an easy-to-use object.

That's the theory, anyway.

There are two SOAP toolkits in common use on PHP. One is called NuSOAP. This works fairly well, but is no longer in active development (it was written before PHP provided its own built-in SOAP class). If you want to use NuSOAP, here is the official project web site: http://nusoap.sourceforge.net/

If you're using PHP5.2 or 5.3 (which you should be, since they're the only currently supported versions), then you'll have a built-in SOAP class. If you want to use the official PHP SOAP class, here's the manual page: http://php.net/manual/en/book.soap.php

Once you've picked which the SOAP class you want to use, you will need to know a bit about SOAP web services in general, and about the specific service you want to use.

Firstly, you'll need to know if the service provides a WSDL. A WSDL is another XML document which defines the methods and parameters available on the SOAP service. This allows your SOAP class to define a class for the SOAP service, which makes life easier for you as a programmer. In practice in PHP it doesn't really make much differench though.

I also recommend you download SOAP UI, which is a debugging tool for SOAP services. It allows you to see and modify the exact XML code being sent and received. It'll help you learn and understand how SOAP works, and also help you with debugging if your PHP code doesn't work as expected.

[EDIT] Obviously the most important thing is to know the API you're working with.

If the service you're dealing with has a WSDL, PHP will automatically generate the appropriate methods for you when you create the object. For example:

$client = new SoapClient("http://somedomain/stockquote.wsdl");
print($client->getStockQuote("MSFT"));

It really is as simple as that. Granted, this is a fairly simple example; most SOAP services (certainly the ones I've used!) take a lot more parameters than that, and they usually take them in the form of a giant nested array structure.

If your service doesn't have a WSDL, you'll have to call the methods using a slightly different method:

$client = new SoapClient(null, array('location' => "http://somedomain/stockquote.asp"));
print($client->__soapCall('getStockQuote',"MSFT"));

Hope that helps you understand it a bit better.

I still recommend having a go with SOAP UI, as it will help you understand SOAP in general a lot better. You should also definitely read the PHP SOAP class manual pages: http://php.net/manual/en/book.soap.php - the documentation is very thorough, though as with all these things it can be daunting to approach at first as it is a reference, not a tutorial.

like image 135
Spudley Avatar answered Sep 24 '22 19:09

Spudley