Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

consume webservice with curl/fsockopen ...

Help
Anonymous
2011-02-18
2013-06-06

  • Anonymous
    2011-02-18

    Hello,

    i have written a little example WS to show my problem.
    Here my WS-Code

    <?php
    ini_set("soap.wsdl_cache_enabled", "0");
    require_once './nusoap/lib/nusoap.php';
    $namespace = "testwebservice";
    $soap = new soap_server();
    $soap->configureWSDL('testwebservice', 'urn:testwebservice');
    $soap->wsdl->schemaTargetNamespace = $namespace;
    // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    // Types for testfunc
    $soap->wsdl->addComplexType(
      'itemin_testfunc',
      'complexType',
      'struct',
      'all',
      '',
      array(
       'id' => array('name' => 'id',
             'type' => 'xsd:int'),
        'floatvalue' => array('name' => 'floatvalue', 
            'type' => 'xsd:float')
      )
    );
    $soap->wsdl->addComplexType(
       'itemin_testfunc_list',
       'complexType',
       'array',
       '',
       'SOAP-ENC:Array',
       array(),
       array(
           array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:itemin_testfunc[]')
       ),
       'tns:itemin_testfunc'
    );
    $soap->wsdl->addComplexType(
      'itemout_testfunc',
      'complexType',
      'struct',
      'all',
      '',
      array(
        'id' => array('name' => 'id',
             'type' => 'xsd:int'),
        'errorcode' => array('name' => 'errorcode', 
            'type' => 'xsd:int')
      )
    );
    $soap->wsdl->addComplexType(
       'itemout_testfunc_list',
       'complexType',
       'array',
       '',
       'SOAP-ENC:Array',
       array(),
       array(
           array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:itemout_testfunc[]')
       ),
       'tns:itemout_testfunc'
    );
    // ##############################################################################
    //function register
    $soap->register('testfunc',
        array('testfunc_input' => 'tns:itemin_testfunc_list'),
        array('testfunc_output' => 'tns:itemout_testfunc_list'),
        'urn:testwebservice',
        'urn:testwebservice#testfunc',
        'rpc',
        'encoded',
        'Testfunction'  
    );
    // ##############################################################################
    // implement function
    function testfunc($parms)
    {
        foreach($parms as $inarray)
        {  
            $retarray[] = array(
                "id" => trim($inarray['id']),
                "errorcode" => "0"
                );
        }
        return $retarray;
    }
    $soap->service(file_get_contents ('php://input'));
    ?>
    

    if i consume the WS from PHP, all works fine

    ini_set("soap.wsdl_cache_enabled", "0");
    $client3 = new SoapClient('http://test.de/testws.wsdl',
                             array('login'    => "",
                                   'password' => "")                 );
    $parray[] = array("id" => "1",
                      "floatvalue" => "3.50"
                      );
    $parray[] = array("id" => "2",
                      "floatvalue" => "6.50"
                      );
                      
    $result = $client3->__soapCall("testfunc", array("testfunc_input"=>$parray));
    echo "<pre>";
    print_r($result);
    echo "</pre>";
    

    The WSDL-File for the service

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:testwebservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:testwebservice">
    <types>
    <xsd:schema targetNamespace="urn:testwebservice">
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
     <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
     <xsd:complexType name="itemin_testfunc">
      <xsd:all>
       <xsd:element name="id" type="xsd:int"/>
       <xsd:element name="floatvalue" type="xsd:float"/>
      </xsd:all>
     </xsd:complexType>
     <xsd:complexType name="itemin_testfunc_list">
      <xsd:complexContent>
       <xsd:restriction base="SOAP-ENC:Array">
        <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:itemin_testfunc[]"/>
       </xsd:restriction>
      </xsd:complexContent>
     </xsd:complexType>
     <xsd:complexType name="itemout_testfunc">
      <xsd:all>
       <xsd:element name="id" type="xsd:int"/>
       <xsd:element name="errorcode" type="xsd:int"/>
      </xsd:all>
     </xsd:complexType>
     <xsd:complexType name="itemout_testfunc_list">
      <xsd:complexContent>
       <xsd:restriction base="SOAP-ENC:Array">
        <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:itemout_testfunc[]"/>
       </xsd:restriction>
      </xsd:complexContent>
     </xsd:complexType>
    </xsd:schema>
    </types>
    <message name="testfuncRequest">
      <part name="testfunc_input" type="tns:itemin_testfunc_list"/></message>
    <message name="testfuncResponse">
      <part name="testfunc_output" type="tns:itemout_testfunc_list"/></message>
    <portType name="testwebservicePortType">
      <operation name="testfunc">
        <documentation>Testfunction</documentation>
        <input message="tns:testfuncRequest"/>
        <output message="tns:testfuncResponse"/>
      </operation>
    </portType>
    <binding name="testwebserviceBinding" type="tns:testwebservicePortType">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="testfunc">
        <soap:operation soapAction="urn:testwebservice#testfunc" style="rpc"/>
        <input><soap:body use="encoded" namespace="urn:testwebservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
        <output><soap:body use="encoded" namespace="urn:testwebservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
      </operation>
    </binding>
    <service name="testwebservice">
      <port name="testwebservicePort" binding="tns:testwebserviceBinding">
        <soap:address location="http://ids-edv.de/shops/demoshop/testws/testws.php"/>
      </port>
    </service>
    </definitions>
    

    Now my question:
    How can i consume the WS using curl or fsockopen ?
    How must the XML-Code look like ?

    I hope, somebody can help me.

    bye jogi

    No my Question:

     
  • Scott Nichol
    Scott Nichol
    2011-03-02

    1. With your PHP client, you could capture network traffic and see the request and response.  I do not know if PHP 5 SOAP has a way to look at the raw request and response directly.

    2. If you change the PHP client to use NuSOAP, you can use NuSOAP's ability to dump the raw request and response and thus see what is being transferred.