What’s the difference between SOAP and Nusoap?

Asked

Viewed 2,276 times

3

I’m having trouble understanding the process of creating a Webservice in PHP.

I created a server who 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 in C: Github Voxy app return index.php:3 Stack trace: #0 C: Github Voxy app retorno 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, from what I read.

If I change the calls, to nusoap_client in the customer’s call, resolve.

But I wanted to know for a fact, where is the problem, and what is the difference between them?

1 answer

1


The error message:

Nusoap "SOAP-ENV: Xml was Empty, didn’t parse" Message

has an apparent solution for this message which is to add an extra element to this part:

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

i.e., the file_get_contents("php://input") and also I made changes in the two files, missed return in function and was making the wrong call on the customer, so the mistake:

Fatal error: Uncaught Soapfault Exception: [Client] Function ("call") is not a Valid method for this

and to work Soapclient a Soapserver, and really the lib used works independent of native functions and are unrelated.


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');

Observing:


This same code can be written easily so 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();

native function gives us much flexibility.

References

  • you would have some example in native SOAP, in PHP ?

  • @Brunnosena I already made the edition with an example referring to yours with the library ... !!! take a look at!

  • Okay, I just saw it. Another question. If I do Webservice with Nusoap. Can I communicate from other languages, just with the URL? If I want to put at the disposal of some partner, to consume this Webservice, will they get ? Or only with native SOAP? What you would recommend to me ?

  • yes. @Brunnosena, the one in your question does not generate WSDL the correct is always generate, I did according to the question, but, yes it is by the address that is consumed!

  • Okay, @Virgilio-novic saw it now. Another question. In case I do Webservice with Nusoap. Can I communicate from other languages, only with the URL? If I want to make it available to some partner, to consume this Webservice, will they get ? Or only with native SOAP? What would you recommend ?

  • 2

    Yes this is the main idea of existing Webservice that other languages and clients consume, but nowadays are using what has a better performance that is the json the famous Webapi.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.