Web Services 使用具有complextype的nusoap的呼叫服务器

hm2xizp9  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(118)

我在浏览器中调用一个客户端,并发送一个数组作为一个参数给一个服务器函数,它返回我的第一个键值对很好,但它只发送给我第二个数组的键,而不是它的值,请帮助我。

客户端

<?php 

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

    $id = array('ID'=>'1234','type' => 'int');

    $MyComplexType = array(
                        'ID'=> $id,
                        'YourName' =>array('YourName' => '123','type' => 'string')
                        );

    //Create object that referer a web services
    $client = new soapclient('http://localhost/server/server2.php');
    //Call a function at server and send parameters too
    $response = $client->call('HelloComplexWorld',$MyComplexType);
    //Process result
    if($client->fault)
    {
      echo "FAULT: <p>Code: (".$client->faultcode."</p>";
      echo "String: ".$client->faultstring;
    }
    else
    {
            echo"<pre>";
            print_r($response);
            echo "</pre>";
            exit();
    }

 ?>

伺服器

<?php 

    require_once("nuSOAP/lib/nusoap.php");
    $namespace = "http://localhost/server/server2.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( 
        'ID' => array(
            'name' => 'ID',
            'type' => 'xsd:int'
            ),
        'YourName' => array(
            'name' => 'YourName',
            'type' => 'xsd:string'
            )

        )
    );

    //Register our method using the complex type
    $server->register(
    // method name:
    'HelloComplexWorld',
    // parameter list:
    array('name'=>'tns:MyComplexType'),
    // 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($mycomplextype)
    {

    return $mycomplextype;
    }

    // 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();

 ?>

输出

Array
(
    [ID] => 1234
    [YourName] => 
)
1dkrff03

1dkrff031#

使用下面的参数可以正确地进行操作,

$MyComplexType = array('ID' => $id ,'YourName' => "Jon Postel");

这给出了

Array
  (
    [ID] => 1234
    [YourName] => "Jon Postel"
 )

相关问题