What is the difference between SOAP and NuSOAP?

3

I'm having trouble understanding the process of creating a WebService in PHP.

I created a server which makes the following call:

<?php
  require_once "lib/nusoap.php";

  $soap = new soap_server;

  $soap->configureWSDL('WS-WebCodeFree', 'http://localhost/ws-webcodefree/');

  $soap->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';

  $soap->register(
        'info',
        array(),        
        array('x' => 'xsd:string'),
        'http://soapinterop.org/'
    );

$soap->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');

function info(){
    return "WebCodeFree - Desenvolvimento Web.";
}

On the client side:

<?php
    include "lib/nusoap.php";

    $client =  new SoapClient('http://localhost/web-service/ws-webcodefree.php?wsdl');

    $result1 = $client->call('info');

It returns me the error:

  

Fatal error: Uncaught SoapFault exception: [Client] Function ("call")   is not a valid method for this service   C: \ GitHub \ voxy \ app \ return \ index.php: 3 Stack trace: # 0   C: \ GitHub \ voxy \ app \ return \ index.php (3): SoapClient-> __ call ('call',   Array) # 1 C: \ GitHub \ voxy \ app \ return \ index.php (3):   SoapClient-> call ('info') # 2 {main} thrown in   C: \ GitHub \ voxy \ app \ return \ index.php on line 3

There seems to be a conflict between NuSoap and SOAP, so I read.

If I switch calls, to nusoap_client in the client call, resolves.

But I really wanted to know where the problem is, and what's the difference between them?

    
asked by anonymous 06.09.2017 / 15:41

1 answer

1

The error message:

  

Nusoap "SOAP-ENV: Xml was empty, did not parse" Message

There is an apparent solution to this message, which is to add one more element in this part:

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) 
    ? $HTTP_RAW_POST_DATA 
    : file_get_contents("php://input");

that is, file_get_contents("php://input") and I also made changes to both files, return was missing in function and was making the wrong call on the client, so from the error:

  

Fatal error: Uncaught SoapFault exception: [Client] Function ("call") is not a valid method for this

and to work SoapClient should be set up SoapServer , and actually% used% works independently of native functions and is not related.

Complete and Functional Code:

Server

<?php

  require_once "lib/nusoap.php";

  $soap = new soap_server;

  $soap->configureWSDL('WS-WebCodeFree', 'http://localhost/ws-webcodefree/');

  $soap->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';

  $soap->register('info',
      array(),        
      array('return' => 'xsd:string'),
      'http://soapinterop.org/'
  );

  function info()
  {
    return "WebCodeFree - Desenvolvimento Web.";
  }

  $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) 
    ? $HTTP_RAW_POST_DATA 
    : file_get_contents("php://input");

  $soap->service($HTTP_RAW_POST_DATA);

Client

<?php
    include "lib/nusoap.php";

    $client = new nusoap_client('http://localhost/ge1/soap_server.php?wsdl', 'wsdl');

    echo $client->call('info');

Note:

This same code can easily be written with SoapClient and SoapServer :

Server

<?php

    function info()
    {
        return "WebCodeFree - Desenvolvimento Web.";
    }
    $options = array(
        'uri' => 'http://localhost/s.php',
        'location' => 'http://localhost/s.php'
    );
    $server = new SoapServer(null,$options);
    $server->addFunction('info');
    $server->handle();

Client

<?php

    $options = array(
        'uri' => 'http://localhost/s.php',
        'location' => 'http://localhost/s.php'
    );
    $client = new SoapClient(null, $options);

    echo $client->info();

The native function gives us a lot of flexibility.

06.09.2017 / 16:02