5

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

Bill
  • 5,478
  • 17
  • 62
  • 95
  • Use a SOAP library. I haven't used one myself in PHP but lots of people who use one of our web services use NuSOAP http://sourceforge.net/projects/nusoap/ It should abstract all the complicated stuff away for you. – Rup Nov 16 '10 at 16:42

3 Answers3

17

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.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • Thanks for the help. I edited the post to show what exactly I need to learn soap for. I want to interact with a specific api (although it would be nice to learn in general) From what I can tell, these services receive a request from a website, and it looks like they send an xml / soap file... I don't really know, I still have to figure it out. – Bill Nov 16 '10 at 19:04
  • 1
    @Phil - I'll add a bit to my answer to try to help more. – Spudley Nov 16 '10 at 19:34
1

Along with the other answers here, I found that I best learned SOAP by learning how to use SOAPUI:

http://www.soapui.org/

It's a great app for debugging your soap interface and helped me a ton trying to figure out what was happening in my PHP calls.

wajiw
  • 12,239
  • 17
  • 54
  • 73