Search code examples
phpweb-servicessoapnusoap

PHP SOAP webservice with NuSOAP gives no result if WSDL is configured


I have a php soap webservice which I've created with using NuSOAP. I use the file 'test.php' to test it in the browser as 'http://www.mydowmain.com:8080/webservice/5/test.php'.

My code:

webservice.php

<?php
 require_once('../lib/nusoap.php');

 $server = new nusoap_server();

 $server ->configureWSDL('server', 'urn:server'); //this line causes to 'no result'
 $server ->wsdl->schemaTargetNamespace = 'urn:server'; //this line causes to 'no result'
 $server -> register('getData');

 function getData ()
 {
   $items = array(array("item1"),array("item2"));
   return $items;
}

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

test.php

<?php
  require_once('../lib/nusoap.php');
  $client = new nusoap_client("http://www.mydowmain.com:8080/webservice/5/webservice.php?wsdl");

  $result = $client ->call('getData');

  print_r($result);
?>

Problem:

If I remove these lines

$server ->configureWSDL('server', 'urn:server'); 
$server ->wsdl->schemaTargetNamespace = 'urn:server';

it shows me the result fine. Otherwise I get a blank screen, get nothing. But I really need to configure the WSDL.

How can I edit the webservice.php so that the WSDL will be configured and I can get the result array on the test.php ?


Solution

  • Try changing this:

    $server ->wsdl->schemaTargetNamespace = 'urn:server';
    

    Into this:

     $server ->wsdl->schemaTargetNamespace = $namespace;
    

    and define $namespace on top of it. That did the trick for me.

    This is my code of my NuSOAP webservice:

    require_once("lib/nusoap.php");
    $namespace = "http://localhost:8080/Testservice/service.php?wsdl";
    $server = new soap_server();
    $server->configureWSDL("TestService");
    $server->wsdl->schemaTargetNamespace = $namespace;