SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Zealot Fiska's Avatar
    Join Date
    Jul 2004
    Location
    Dardania - Ancient Illyria
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question SOAP - web service

    Hi,
    I'm currently learning soap and its implementation with php 5.
    I have couple of questions, perhaps experienced ones might wanna help me :

    - Is it possible with SOAP to download a file from remont client? if yes how? perhaps a link to a tutorial?
    - How to generate WSDL, can it be done automatically, or you have to type it by hand, is there any SOAP function built in PHP5 so that does WSDL automatically?

    thanx in prior
    Fiska
    let's make things easier

  2. #2
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fiska
    Hi,
    I'm currently learning soap and its implementation with php 5.
    I have couple of questions, perhaps experienced ones might wanna help me :

    - Is it possible with SOAP to download a file from remont client? if yes how? perhaps a link to a tutorial?
    - How to generate WSDL, can it be done automatically, or you have to type it by hand, is there any SOAP function built in PHP5 so that does WSDL automatically?

    thanx in prior
    Fiska
    - you cannot download a file with SOAP. all comunications are done with XML, but you can pass an URL to that file if the communication is between 2 servers.
    - WSDL (Web Services Description Language) is a language based on XML and it is used to describe web services. SOAP is built on top of WSDL.

    PHP5's implementation of SOAP is rather low level, and until a higher level library that's built on top of PHP5's implementation appears, I recommend you that you use NuSOAP: http://dietrich.ganx4.com/nusoap/index.php

  3. #3
    SitePoint Zealot Fiska's Avatar
    Join Date
    Jul 2004
    Location
    Dardania - Ancient Illyria
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - WSDL (Web Services Description Language) is a language based on XML and it is used to describe web services. SOAP is built on top of WSDL.
    thanx but I was asking on how to generate the WSDL not the meaning cuz I'm already familiar with WSDL
    let's make things easier

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    PA, USA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out the SOAP 1.2 Attachment feature; I think that might give you what you want:

    http://www.w3.org/TR/2004/NOTE-soap1...08/#properties
    "Outside of a book, dog is mans best friend.
    Inside of a dog, its too dark to read" - Groucho Marx

  5. #5
    SitePoint Evangelist jplush76's Avatar
    Join Date
    Nov 2003
    Location
    Los Angeles, CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you mimic a file download with soap... for example your soap server sits there, the soap client connects and starts sending you the actual data of the file with the file information (name, when the data is over and you can write the file). This is how I've done file updates on several projects. Create a soap server on your project, then if you release a patch you connect to those endpoints and send your files, works perfect.

    as far as generating wsdl you can look here
    http://www.scottnichol.com/nusoapprogwsdl.htm

    nusoap allows you to do this, php5 does not yet however there are a bunch of projects in the works that will address that need shortly.
    My-Bic - Easiest AJAX/PHP Framework Around
    Now Debug PHP scripts with Firebug!

  6. #6
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a simple rpc/encoded wsdl autogenerator that you might find helpful, PHP5 only though.

  7. #7
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I once had an example somewhere hold on......., ah there it is...

    here we go....

    Supplier....
    PHP Code:
    <?php


        
    //Eerst een check op de extentie maken...
        
    if (!extension_loaded('soap')){
            
    $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' '';
            
    dl($prefix 'soap.' PHP_SHLIB_SUFFIX);
        }

        
        
        class 
    foo{
            
            function 
    sayHello($name){
                
    $salutation "You, $name, will be delighted to know i am working!";
                return(
    $salutation);
            }
            
        }
        
        
            
        function 
    sendObject(){
            return(new 
    foo());
        }

        
    //Create Server
        
    $soapServer = new SoapServer("../resources/greetings.wsdl");
        
        
    $soapServer->setClass("foo");
        
    //$soapServer->addFunction("sendObject");
        
    $soapServer->handle();
        
        
    ?>
    Client...
    PHP Code:
    <?

        
    if (!extension_loaded('soap')){
            
    $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' '';
            
    dl($prefix 'soap.' PHP_SHLIB_SUFFIX);
        }

        if(
    $client = new SoapClient("../resources/greetings.wsdl")){
            
    $var "Boy";
            echo 
    $client->sayHello($var);    
            echo 
    $client->doc;
        }
        
        
        
    ?>
    WSDL
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!--
    	As you can see from this first part of the xml, we define which version of xml we are using
    	(1.0), and then declare the definitions element. This element must always be your root element
    	and gives the name of the web-service as well as defines target namespace for use in the document.
    -->
    <definitions name="greetings" 
    	targetNamespace="http://localhost/myapp/driver/sayHello" 
    	xmlns:tns="http://localhost/myapp/driver/sayHello" 
    	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    	xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    	xmlns="http://schemas.xmlsoap.org/wsdl/">
    	
    	<!--
    		These are the message elements. This section gives the request and response message names and defines
    		the types they will use (see documentation http://www.php.net/manual/en/ref.soap.php).
    	-->
    	<message name="sayHelloRequest">
    		<part name="name" type="xsd:string" />
    	</message>
    	<message name="sayHelloResponse">
    		<part name="salutation" type="xsd:string" />
    	</message>
    
    	<!--
    		The portType describesa full round-trip operation called sayHello, which consists of the input and output messages sayHelloRequest
    		and sayHelloResponse .
    	-->
    	<portType name="sayHelloPortType">
    		<operation name="sayHello">
    			<input message="tns:sayHelloRequest" />
    			<output message="tns:sayHelloResponse" />
    		</operation>
    	</portType>
    	
    	<!-- 
    		Notice that, in the following code-snippet, we give the binding a name and then define it's type to be sayHelloPortType.
    		What this means is that we are really defining this binding for the portType sayHelloPortType, which is the portType that has just been
    		defined. Further, we define the binding style, in this case RPC, as well as the transport mechanism. Beceause we are using HTTP,
    		we specify the soap http transport. Note that this section also defines the type of encoding to use for the body of the soap message.
    		In this case it is encoded, other methods could be a document or a literal use attribute.
    	-->
    	<binding name="sayHelloBinding" type="tns:sayHelloPortType">
    		<soap:binding stype="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    		<operation name="sayHello">
    			<soap:operation soapAction="" />
    			<input>
    				<soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
    			</input>
    			<output>
    				<soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
    			</output>
    		</operation>
    	</binding>
    	
    	<!--
    		Just to humor people no obligations to integrate this part.
    	-->
    	<documentation>
    		This is a soap server example for myapp!
    	</documentation>
    	<!-- 
    		Finaly we define a single endpoint with the port element, given the address of the actual service to use.
    		In this case its allready a part of myapp but u could also use a port to another server.
    	-->
    	<service name="sayHelloService">
    		<port name="sayHelloPort" binding="sayHelloBinding">
    		<soap:address location="http://localhost/myapp/driver/driver.supplier.php" />
    		</port>
    	</service>
    </definitions>
    Hope it helps

    Cheers,
    Galo
    Business as usual is off the menu folks, ...

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that you might find helpful, PHP5 only though.
    We don't mind if it's PHP5, thanks for the forsight btw

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wonder if generating a WSDL on .NET and using it within PHP as server would work?

  10. #10
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I've been able to find out, the PHP5 soap server only supports rpc/encoded WSDL.

  11. #11
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tanus
    As far as I've been able to find out, the PHP5 soap server only supports rpc/encoded WSDL.
    Actually you CAN make a doc/lit service using the extension. The majority of the changes are in the WSDL. I don't have any sample code off hand, but I've written one as a test to decide how hard moving away from a PEAR::SOAP server to the new PHP5 extension would be. My recommendation? Don't use the extension, it's less flexible, less intuitive, and the speed gains are marginal.

  12. #12
    SitePoint Evangelist jplush76's Avatar
    Join Date
    Nov 2003
    Location
    Los Angeles, CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    speed gains can be huge depending on the amount of data that needs parsing. Thats the real speed boost to the new php5 extension is parsing all the xml in C space as opposed to user space like in nusoap for example. I've benchmarked performance tests with 160K of data with the soap extension showing an average of 250-350% speed improvement.

    If you're parsing smaller amounts of data like some simple soap queries that return 1K of data, the speed improvements obviously won't be as noticeable but I do alot of heavy data transfer and its really made a huge difference.
    My-Bic - Easiest AJAX/PHP Framework Around
    Now Debug PHP scripts with Firebug!

  13. #13
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not used PHP5 extension but I'd be looking forward to doing so, but could Web Services be used, easilly, to transfer binary files from one server to another? Files such as JPEGs or ZIPs?

    Also, slightly off topic I know (sorry) but has anyone used Web Services as a means to create an application installation, so such a way that it could report back if there were difficulties during the installation?

    Thanks

  14. #14
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Not used PHP5 extension but I'd be looking forward to doing so, but could Web Services be used, easilly, to transfer binary files from one server to another? Files such as JPEGs or ZIPs?

    Also, slightly off topic I know (sorry) but has anyone used Web Services as a means to create an application installation, so such a way that it could report back if there were difficulties during the installation?

    Thanks
    Sure it could, I can't imagine it's easier than using FTP/SFTP/RSYNC. Using either SOAP attachments or even base64 encoding the data directly into the envelope (easier but NOT recommended), it would be relatively easy to transfer just about anything you want between servers/platforms/languages.

  15. #15
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sgarissta
    Sure it could, I can't imagine it's easier than using FTP/SFTP/RSYNC. Using either SOAP attachments or even base64 encoding the data directly into the envelope (easier but NOT recommended), it would be relatively easy to transfer just about anything you want between servers/platforms/languages.
    And what is wrong with plain old HTTP and plain fsocketopen or curl or even fopen in PHP5 (because now they included the http wrappers) ?
    Why do you have to make your life difficult ?

  16. #16
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bonefry
    And what is wrong with plain old HTTP and plain fsocketopen or curl or even fopen in PHP5 (because now they included the http wrappers) ?
    Why do you have to make your life difficult ?
    Never once did I say or imply that it was the easiest way, in fact I believe I mentioned several alternatives I thought to be easier. That said, SOAP is just a data protocol, it assumes nothing about the underlying transmission protocol. SOAP is capable of being used on top of standard TCP/IP, HTTP, even SMTP. SOAP is capable of being stateful.

    So yes, there are often easier (or more efficient) alternatives to any problem, SOAP does still have its place, especially when trying to come up with a "standard interface" to a set of functions or data that can be remotely accessed from a variety of languages and environments. It's far from perfect, but is very useful at times.


Bookmarks

Posting Permissions

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