Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: SOAP or no SOAP

  1. #1
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts

    SOAP or no SOAP

    So I have this client, I love clients at times. Wanted an API, web API to make communication between X program and another X program on another server in the same building. So after 3 meetings with this client I told them yes, I could make a PHP app that would accept POST call's and send data back in XML format by simply echoing data in XML format back (since they said the returned data had to be in XML). So I thought easy enough yeah sure.

    I told them exactly 100% how I would do it, they gave me the requests they would be making to the API and what needed to be returned. Simple, until after they accepted the bid and I asked, "How are you going to be making these requests; PUT, POST or GET?".

    Bad questions to ask, there initial software is in .NET, so they proceeded to tell me, well none of those (acting really pretentious towards me in this conversation ha ha). We REQUIRE that your application be WSDL and SOAP communication and return us an XML FILE! All pretentious and obnoxious like ha ha

    Now, what the heck is that?? I have googled SOAP and know PHP has an interpreter for it, but have never used it. But on the WSDL page I couldn't really understand what the heck that was ha ha

    I really want to say the heck with it and find another programmer since I told them originally how I would do it and it's not my fault they don't listen.

    Could I not just tell them, yeah sure, and do it my original way and just echo out XML format in the way they want it an they will never know the difference? (I am asking this since I don't know what the heck WSDL is and how it works with SOAP or why they would want SOAP anyways if they can just program in an XML parser and send post requests to my file ha ha)

    They told me they would make their requests to my file this way:

    Code:
    objeto = new MSSOAP.SoapClient30
    objeto.mssoapinit("http://ip/servicio.wsdl", "", "")
    
    xml_respuesa = objeto.metodo(xml_parametros)
    Or do I just throw in the towel because they are pretentious jerks ha ha ha.

    Thanks for any advise.
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    SOAP itself is easy as pie. The problem is always PHP's datatype weakness which tends to grind some things you'd expect to be easy to a halt :/
    WSDL generation itself is quite complicated. I'm willing to bet there are generators out there to write it for you though. Basically they explain what the simple object is, and how you talk to it.
    Looks to me like you have a WSDL already available? That can simply be used to open a SOAPClient (or look at using nusoap, I just use the builtin since they are easy enough), and then you kinda treat it like a PHP object. Yes it has to be object oriented though (although you can certainly write procedural methods to treat it this way, the communication with the builtin soapclient and soapserver are both object oriented).
    PHP is almost identical to the above:
    PHP Code:
    $client = new SOAPClient('http://ip/wsdl.wsdl');
    $result $client->__soapcall('metodo', array('parameters')); // This is chained to __call, which means you can just use $client->metodo(). 
    Simple as that.

    Server is similar, but backwards. You typically choose the wsdl that describes yourself, register the methods that handle all the input and output available, and then set a handling listener. Away it goes, clients would simply use soapclients.

    As for XML output, SOAP itself is an XML format. Is that what they mean or do they actually want your results in XML? Both are easy enough, properly formatted HTML is really just a form of XML (if using single ended tags properly such as in XHTML and not in HTML, although schema/DTD dictates if you can do that).

    Ultimately, the most difficult thing of SOAP generation is the creation of the WSDL, which you actually learn to do fairly quickly (and I assume generators exist; I built a reflector a few years ago that did just this task). Beyond this, its learning how to pass the parameters, and worst of all, figuring out what PHP did wrong with the exceptionally complex datatypes when it didn't properly create it as your desired type or stdclass.

    Edit:
    Oh btw, since you kinda mentioned it. You can certainly handle soap in a manual fashion. You will be given an XML file of a soap envelope, and you can pick it a part to determine what it is that it wants, and handle your scripts accordingly. IMO, this is a lot more work to do than using a soapserver. Likewise, you can manufacture all of your soap requests from simple strings or XML, but it is also more difficult than the two lines I have above there.
    Oh, I should mention that overall debugging is also a nightmare in soap. Reason being is that so many thing can catch you, and its difficult to identify the problem as either the client or server.
    Last edited by Fou-Lu; 11-25-2011 at 04:04 AM.

  • #3
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Hmm, ok. No actually the WSDL doesn't exist, that was just their example of what they wanted. I have to create the WSDL file myself.

    You mentioned SOAPServer, do I need a SOAP server app running on the machine with apache and PHP? Or was this just a term used for my PHP script?

    As for XML output, SOAP itself is an XML format. Is that what they mean or do they actually want your results in XML?
    From what I understand they want it in XML format, although their original email said they wanted an XML file, which doesn't make any sense to me. So I figure just XML format if they are calling on my file for each request.

    Thanks Fou.
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #4
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    What I don't understand is this, if they make a call to the WSDL file (which they are doing in the above code), then how does my PHP script know they are calling it for information and return info? Or does the WSDL file redirect the call to a script I have defined in it somewhere?

    Also for their incoming calls, do I just create a Class and then a function for each definition I create in the WSDL file? Then when that WSDL file calls my script it immediately calls that function which will echo (return) the information requested?

    That's what has me boggled :S ha ha
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The way soap works is that the client (may, its not actually required but is more hit and miss) loads the WSDL file. The WSDL file tells the soap client where to connect to in order to invoke methods from the soap server. SOAPServer is simply a handling class in PHP, it runs just as any other script, but attaching directly will give unusual results if any at all.
    The WSDL will specify the port binding and within it is the address of where to contact for the method to invoke - that's how it knows where to go.
    The WSDL file itself does nothing. Its job is to tell the client (no matter what language it is, as long as its a soapclient) where to go to retrieve information from, and how to actually talk to the methods presented by the soapserver. Check this link for a quick example of a WSDL file: http://www.w3.org/2001/03/14-annotated-WSDL-examples

    With an established soapclient and soapserver, the client now requests data from the soapserver via method calls. Its almost like running a simple:
    PHP Code:
    require_once '/myclass.class.php';
    $server = new MyClass(); // options or wsdl would be here, but this is just 'MyClass'.

    $fQuote $server->getLastTradePrice('AAPL');
    printf('Apple\'s last trade price: %0.2f'$fQuote); 
    (for example from the second WSDL in the given link).
    Personally I use __soapCall instead of the override for __call; the above would likely complain in my IDE if I use an actual soapclient, since it can't actually find a method called getLastTradePrice. Runtime would be fine.

    The only difference really is that the soapclient is a remote access to a method, while the include is a local one. Client wise, it doesn't really see a difference.

  • #6
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Aha, ok got it, so basically the WSDL is a definition file, or better yet a class Map to the different functions for each client to know what it can and cannot do. Got it, thanks Fou
    "FORTRAN is not a language. It's a way of turning a multi-million dollar mainframe, into a $50 programmable scientific calculator."
    http://www.microfastcat.com -- FastCat Software, the fastest software on the NET!
    http://www.microthosting.com -- Free reseller web hosting, Hosting, VPS, FREE SMALL HOSTING!!!
    http://www.microtronix-tech.com -- Web design and programming

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Definition file is the best description of it. WSDL = Web Services Definition Language


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •