本文介绍了php web services(nusoap)中没有返回复杂的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这里我创建了两个函数

1)第一个函数返回单行结果

2)第二个函数返回一个像结果数组的结果复数。



第一个函数工作正常,当我调用第二个函数时它没有返回结果



你能告诉我哪里出错了吗?



我的PHP代码是



//index.php



Hi all,

here I created two function
1) first function return a single line of result
2) second function return a complex of result like array of result.

first function is working fine, when I invoke second function it's not returning result

could you tell me where I went wrong?

my php code is

//index.php

<?php


require_once("nuSOAP/lib/nusoap.php");

$namespace = "http://localhost/nusoaphelloworld/index.php";
// create a new soap server
$server = new soap_server();
// configure our WSDL
$server->configureWSDL("HelloExample");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;

//Register a method that has parameters and return types
$server->register(
                // method name:
                'HelloWorld',
                // parameter list:
                array('name'=>'xsd:string'),
                // return value(s):
                array('return'=>'xsd:string'),
                // namespace:
                $namespace,
                // soapaction: (use default)
                false,
                // style: rpc or document
                'rpc',
                // use: encoded or literal
                'encoded',
                // description: documentation for the method
                'Simple Hello World Method');

//Create a complex type
$server->wsdl->addComplexType('MyComplexType','complexType','struct','all','',
        array( 'contact' => array('name' => 'contact','type' => 'xsd:string'),
               'email' => array('name' => 'email','type' => 'xsd:string')));

//Register our method using the complex type
$server->register(
                // method name:
                'HelloComplexWorld',
                // parameter list:
                array(),
                // return value(s):
                array('return'=>'tns:MyComplexType'),
                // namespace:
                $namespace,
                // soapaction: (use default)
                false,
                // style: rpc or document
                'rpc',
                // use: encoded or literal
                'encoded',
                // description: documentation for the method
                'Complex Hello World Method');

//Our Simple method
function HelloWorld($name)
{
    return "Hello " . $name;
}

//Our complex method
function HelloComplexWorld()
{
    //return $mycomplextype;
    $result = array();
    $result[] = array( 'contact' => 'Manoj', 'email' => '[email protected]');
    $result[] = array( 'contact' => 'munna', 'email' => '[email protected]');

    return $result;
}

// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();

?>





// client.php





//client.php

/**
 * @author
 * @copyright 2013
 */

require 'nuSOAP/lib/nusoap.php';

$response = new nusoap_client('http://localhost:8080/myfiles/nusoaphelloworld/index.php?wsdl');

$result = $response->call('HelloWorld',array('name'=>'Manoj'));

$result1 = $response->call('HelloComplexWorld',array());

print_r($result);

echo '<br/><br/>';

print_r($result1);

//echo '<br/><br/>';

//var_dump($result1);





我的结果是:



第一个功能结果是:Hello Manoj



第二功能结果是:



数组



[联系] =>

[email] =>





这里没有显示结果?



任何人都可以告诉我哪里出错了?



提前感谢... .......



my result is:

First function result is : Hello Manoj

Second function reslut is:

Array
(
[contact] =>
[email] =>
)

here not displaying result ?

anyone can tell me where I went wrong?

thanks in advance..........

推荐答案




这篇关于php web services(nusoap)中没有返回复杂的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:31