Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

SOAP, WSDL, XML service/client

by agentorange (Sexton)
on Sep 09, 2013 at 16:22 UTC ( #1053034=perlquestion: print w/replies, xml ) Need Help??

agentorange has asked for the wisdom of the Perl Monks concerning the following question:

A few months ago I dabbled with SOAP and was ok calling a service and getting data from it. Trouble is not touched Perl since but I'd like to write a prototype to further my knowledge though am not entirely clear where to start.

I'd like to write a service that listens on a port with no need for a separate web server (ie. Apache). It would receive XML in a specific format and then act upon that data. I also need a client to test it.

Reading up it seems like I need:

  • SOAP::Lite for the server and client
  • WSDL service on the server
  • XML::LibXML to parse the XML
  • But I'm not entirely sure how this all hangs together and the more I google the more confused I become. This would seem a very straight forward a task but every example I've seen seems more complex and/or relies on Apache and inserting the Perl as CGI.

    Does anyone have a sample bit of code that view? ie. Basic server to receive two tags in an XML file over a port? Tend to find I need examples to get me that initial leg up!

    Any help would be greatly appreciated.

    Replies are listed 'Best First'.
    Re: SOAP, WSDL, XML service/client
    by jhourcle (Prior) on Sep 09, 2013 at 16:49 UTC

      You don't need XML::LibXML, as SOAP::Lite does the unpacking for you.

      As for the WSDL, if you're only going to be calling this from SOAP::Lite, and will never need to use another language to access it, you can probably ignore that part, too. (SOAP::Lite will handle *most* things correctly when serializing, but if you have a string that looks like a number, it could flag it as an integer, and then strictly typed languages get really, really upset).

      For the sample code, take a look at the SOAP::Lite cookbook. It covers all of your questions. (the webserver-less version is SOAP::Transport::HTTP::Daemon)

        Thank you.

        Looks like I can make use of "dispatch_to(..)" to process the XML as well.

        I will need WSDL though. I've a project spinning up and I can see that a web service for a tiny part of it will be really useful and I know the other guys will be querying it with something other than Perl. Probably Java.

          Creating a WSDL ater the fact, especially if you have complex structures (hashes of arrays of hashes of hashes) gets really, really messy. I'd highly recommend reading Which style of WSDL should I use? and Re: Starting on SOAP before you even start.

          As you're using a WSDL file, you can drop the typing of each and every variable, and go with RPC/literal or doc/lit wrapped. (RPC/encoded, which is SOAP::Lite's default is useful if you don't have a firm specification, and the clients are flexible enough to deal with changes, but it causes no end of headaches with C and Java clients if something gets typed wrong)

          There are also some absolutely awful SOAP services out there -- the strangest one that I have to deal with, the programmers obviously didn't understand SOAP, because they return a single value (an XML encoded string, that has multiple values encoded in it).

    Re: SOAP, WSDL, XML service/client
    by Anonymous Monk on Sep 09, 2013 at 21:22 UTC

    Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlquestion [id://1053034]
    Front-paged by Arunbear
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (4)
    As of 2022-01-18 23:21 GMT
    Find Nodes?
      Voting Booth?
      In 2022, my preferred method to securely store passwords is:

      Results (54 votes). Check out past polls.