English 中文(简体)
Can nusoap returns arrray of string?
原标题:

I would like to return an array of string in my web services

I ve tryed :

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

$server = new soap_server();
$server->configureWSDL( NewsService ,  urn:NewsService );
$server->register( GetAllNews , 
 array(),
 array( return  =>  xsd:string[] ),
  urn:NewsService ,
  urn:NewsService#GetAllNews ,
  rpc ,
  literal ,
   
);

// Define the method as a PHP function
function GetAllNews()
{
 $stack = array("orange", "banana");
 array_push($stack, "apple", "raspberry");
 return $stack;
}

but it doesn t work. What is the correct syntax for that ?

Thanks in advance for any help

问题回答

You can t return an array like this. To return an array, you have to define a complex type. I ll provide u an example...

The server program service.php:

    <?php
// Pull in the NuSOAP code
require_once( lib/nusoap.php );
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL( RM ,  urn:RM );

//Define complex type
$server->wsdl->addComplexType(
  User ,
  complexType ,
  struct ,
  all ,
   ,
 array(
   Id  => array( name  =>  Id ,  type  =>  xsd:int ),
   Name  => array( name  =>  Name ,  type  =>  xsd:string ),
   Email  => array( name  =>  Email ,  type  =>  xsd:string ),
      Description  => array( name  =>  Description ,  type  =>  xsd:string )
  )
);


// Register the method
$server->register( GetUser ,     // method name
 array( UserName =>  xsd:string ),         // input parameters
 array( User  =>  tns:User ),     // output parameters
  urn:RM ,         // namespace
  urn:RM#GetUser ,     // soapaction
  rpc ,          // style
  encoded ,         // use
  Get User Details       // documentation
);

function GetUser($UserName) {

    return array( Id  => 1, 
        Name  => $UserName,
        Email  => test@a.com ,
        Description  => My desc 
       );

}

// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA :   ;
$server->service($HTTP_RAW_POST_DATA);
?>

And the client program client.php:

<?php
// Pull in the NuSOAP code
require_once( lib/nusoap.php );
// Create the client instance
$client = new soapclient( http://localhost/Service/service.php );
// Call the SOAP method
$result = $client->call( GetUser , array( UserName  =>  Jim ));
// Display the result
print_r($result);
?>




相关问题
IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

ASP.net web services

I am using a web service which sets the Thread.CurrentPrincipal object while logging in and soon later when another webmethod of the same web service accesses Thread.CurrentPrincipal, its different/...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

热门标签