NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
ASAP: need help with nusoap server, client


Joined: 02 May 2007
Posts: 4
Reply with quote
hello,

i'm newbie with nusoap. I have read few tutorials and created server and client,
but client is not working or maybe i have error in server, i have no idea...

please help me

--------------------------------------------------------------------------------------------

here is server:
Code:
<?php

   require_once '../nusoap/lib/nusoap.php';
   
   $ns = "http://localhost/makePhp/service.php";
   
   $server = new soap_server();
   
   $server->configureWSDL('Service', $ns);
   
   $server->wsdl->schemaTargetNamespace = $ns;
   
   $server->wsdl->addComplexType(
      'Stats',
      'complexType',
      'struct',
      'all',
      '',
      array(
         'Unique' => array('name' => 'Unique', 'type' => 'xsd:decimal'),
         'All' => array('name' => 'All', 'type' => 'xsd:decimal')
      )
   );
   
   $server->register(
      'getStats',
      array(),
      array('return' => 'tns:Stats'),
      $ns
   );
   
   $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
   
   $server->service($HTTP_RAW_POST_DATA);
   
   function getStats()
   {
      $result = array('Unique' => 0, 'All' => 0);
      
      return $result;
   }
   
?>



Here is client:
Code:
<?php
   
   require_once '../nusoap/lib/nusoap.php';
   
   $client = new soapclient('http://localhost/makePhp/service.php?wsdl', true);
   
   $err = $client->getError();
   if ($err)
   {
      echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
   }
   
   $param = array();
   
   $result = $client->call('getStats', $param);
   
   if ($client->fault)
   {
      echo '<h2>Fault</h2><pre>';
      print_r($result);
      echo '</pre>';
   }
   else
   {
      $err = $client->getError();
      if ($err)
      {
         echo '<h2>Error</h2><pre>' . $err . '</pre>';
      }
      else
      {
         echo '<h2>Result</h2><pre>';
         print_r($result);
         echo '</pre>';
      }
   }
   
?>
View user's profileFind all posts by elbrusSend private message


Joined: 02 May 2007
Posts: 4
Reply with quote
i'll try to explain, what i'm doing, what i need

i need to create web service: service.php,
which will return 'unique' and 'all' statistics,
in my provided server code it will return 0 for both values

it looks that server works good, because i see such view:
--------------------------------------------------------------------------------------
Service

View the WSDL for the service. Click on an operation name to view it's details.

* getStats
--------------------------------------------------------------------------------------

and it generates wsdl file too

but all the problems starts at client side:
1. execution is very long
2. execution stops at ... new soapclient(...) line

and one more thing:
if i'll write in my browser such row: http://localhost/makePhp/service.php/getStats
what should happen ? it will execute getStats function or what ?
for me it shows the same view like http://localhost/makePhp/service.php
View user's profileFind all posts by elbrusSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
you may want to check this post error-retrieving-data-from-nusoap-webservice-t3091.html
It works with complex types and returns them.
I hope you'll manage to get your code to work easily too.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 02 May 2007
Posts: 4
Reply with quote
Quote:
you may want to check this post error-retrieving-data-from-nusoap-webservice-t3091.html
It works with complex types and returns them.
I hope you'll manage to get your code to work easily too.


i changed my server in the same way, like it is shown in that post
the code:
Code:
<?php

   require_once 'nusoap.php';
   
   $ns = "http://localhost/makePhp/service.php";
   
   $server = new soap_server();
   
   $server->configureWSDL('Service', $ns);
   
   $server->wsdl->schemaTargetNamespace = $ns;
   
   $server->wsdl->addComplexType(
      'Statistic',
      'complexType',
      'struct',
      'all',
      '',
      array(
         'Name' => array('name' => 'Name', 'type' => 'xsd:string'),
         'Value' => array('name' => 'Value', 'type' => 'xsd:int')
      )
   );
   
   $server->wsdl->addComplexType(
      'Statistics',
      'complexType',
      'array',
      '',
      'SOAP_ENC:Array',
      array(),
      array(
         array('ref' => 'SOAP_ENC:arrayType', 'wsdl:arrayType' => 'tns:Statistic[]')
      ),
      'tns:Statistic'
   );
   
   $server->register(
      'getStats',
      array('input' => 'xsd:int'),
      array('return' => 'tns:Statistics'),
      $ns
   );
   
   $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
   
   $server->service($HTTP_RAW_POST_DATA);
   
   function getStats($params)
   {
      $result = array(0 => array('Name' => 'Unique', 'Value' => 111),
                  1 => array('Name' => 'All', 'Value' => 222)
                  );
      // i deleted few lines here for security purposes
      return $result;
   }
   
?>



but it still crashes at client side on this line:
Code:
$client = new soapclient('http://localhost/makePhp/service.php?wsdl', true);



i tried to use web service with .NET 2005, it finds my method getStats,
but it returns such errors:
The document at the url http://localhost/makePhp/service.php?wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:
    Report from 'DISCO Document' is 'Discovery document at the URL http://localhost/makePhp/service.php?wsdl could not be found.'

    The document format is not recognized.

    Report from 'WSDL Document' is 'There is an error in XML document (15, 21).'

    Namespace prefix 'SOAP_ENC' is not defined.

    Report from 'XML Schema' is 'The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.'



maybe thats the same reason, why it is not working with php client
waiting for any ideas.....
View user's profileFind all posts by elbrusSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
probably you have php_soap.dll enabled.
Unfortunately, php_soap developers used the same class names as were originally used in NuSoap and obviously it results in name conflict.
I'd recommend you to download the latest nusoap from sf.net and change all classes in your code to "nu" prefixed ones.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 02 May 2007
Posts: 4
Reply with quote
4 or 5 days ago I downloaded latest version of nuSoap

and yes, then i had soap.dll enabled, but it returned me an error, that classes names are the same

so I disabled soap.dll and there was no problem of such type

but after that all the time I have problems with client, the code looks good, but
still something is buggy

if i'll find source of problem, i'll post it here
View user's profileFind all posts by elbrusSend private message
ASAP: need help with nusoap server, client
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic