CodeIgniter Web Services Client

13,032

Solution 1

It looks as if your webservice is using SOAP (simple object access protocol). This is not REST. You'll want to use PHP's built in Soap extension with the SoapClient class. This way it's easy to post a XML "request" to that page which will return xml results rather than a html view (I assume).

  1. Check Soap the soap extension is loaded on your server
  2. Read about the SoapClient http://php.net/manual/en/class.soapclient.php
  3. See if that webservice offers a WSDL (web service description language) file.
  4. Create an instance of a soap client, using the wsdl and call the function you require.

Simple example from PHP.net

$client = new SoapClient("http://localhost/code/soap.wsdl");
$something =  $client->HelloWorld(array());
echo $something->HelloWorldResult;

Solution 2

To get a xml response, you do not need Codeigniter. Specifically it provide WSDL. At http://services.insw.go.id/web-services/nsw you can find the example as

String wsdlUrl = "http://services.insw.go.id:80/web-services/nsw?WSDL";

So the WSDL API would be http://services.insw.go.id:80/web-services/nsw?WSDL

Then you can check this page to see how to install soap for your php.

Then you can get a xml response by the following code:

$client = new SoapClient('http://services.insw.go.id:80/web-services/nsw?WSDL');
//var_dump($client->__getFunctions()); 

$response = $client->getListGA();
echo $response;

these code do not need Codeigniter.

Note: $client->__getFunctions() will show you all functions that the WSDL support and the parameters the functions need.

Good luck

Share:
13,032

Related videos on Youtube

Igi Shellshock
Author by

Igi Shellshock

Updated on June 04, 2022

Comments

  • Igi Shellshock
    Igi Shellshock almost 2 years

    I'm a newbie at CI, and I want to retrieve XML data from web services WebLogic, the server that is located at: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA . I want to to get the XML response from the server. How should I do this?

    I made this function on controllers (resttest.php)

    public function getRest()
    {
        $this->rest->initialize(array('server' => 'http://services.insw.go.id'));
    
        $lartas = $this->rest->get('web-services/nsw',array('operation.invoke' => 'getListGA'),'xml');
        die(var_dump($lartas));
    }
    

    Sometimes I get an error like "array(0) { }" and if I refresh, I get all HTML view, the same as when I browse to: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA

    Am I wrong, or missing some step, or do you have any suggestion about how to change this code?