在PHP中将多维数组传递给soap complexType

我从邮件服务器上发了一些电子邮件.有一个函数应该拉这些电子邮件并返回一个多维数组.我在客户端Web服务器中使用此数组来为我完成这项工作.我不知道如何将此数组传递给soap complexType.我写了以下代码:

$server->wsdl->addComplexType(
'MailTicket',
'complexType',
'struct',
'all',
'',
 array(
    'attachment' => array('name' => 'attachment', 'type' => 'xsd:string'),
    'body' => array('name' => 'body', 'type' => 'xsd:string'),
    'accountID' => array('name' => 'accountID', 'type' => 'xsd:string')
 )
);

$server->wsdl->addComplexType(
 'MailTicketReturn',
 'complexType',
 'struct',
 'all',
 '',
 array(
    'Done' => array('name' => 'result', 'type' => 'xsd:string')
 )
);

   // Register the method to expose
   $server->register('createMailTicket',                    // method name
 array('mailTicketData' => 'tns:MailTicket'),          // input parameters
 array('return' => 'tns:MailTicketReturn'),    // output parameters
 'urn:eticketing',                         // namespace
 'urn:eticketing#createMailTicket',                   // soapaction
 'rpc',                                    // style
 'encoded',                                // use
 'create a ticket by mail'        // documentation
);

在客户端,我写道:

require_once('nusoap.php');
$wsdlURL="http://127.0.0.1/eticket/ETKWS.php?wsdl";
$client = new nusoap_client($wsdlURL,true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;


$finalArray=Array
(
  [attachment] => Array
    (
        [0] => Array
            (
                [0] => file1
                [1] => file2
            )

        [1] => Array
            (
                [0] => file1x
            )

    )
[body]=>Array
            (
                [0] => some text
                [1] => some other text
            )

[accountID] => Array
    (
        [0] => 5464654
        [1] => 4654664
    )

)

if(is_array($finalArray)) // creat new tickets
{
 $result=$client->call('createMailTicket',$finalArray);
}

$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) .       '</pre>';
exit();
}

我收到了这个错误:

构造函数错误

在第1行解析SOAP有效负载的XML错误:格式不正确(无效令牌)

最佳答案 NuSOAP支持返回多维数组(xsd:Array)

           $server= new nusoap_server();

            $namespace = "http://localhost/webservice/";
           // create a new soap server
           $server = new nusoap_server();
           // configure our WSDL
           $server->configureWSDL("WebServices212");
           // set our namespace
           $server->wsdl->schemaTargetNamespace = $namespace;          

           $server->register(
            // method name:
            'test',          
            // parameter list:
            array('id'=>'xsd:int'), 
            // return value(array()):
            array('return'=>'xsd:Array'),
            // namespace:
            $namespace,
            // soapaction: (use default)
            false,
            // style: rpc or document
            'rpc',
            // use: encoded or literal
            'encoded',
            // description: documentation for the method
            'documentation');

             $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);  

客户

           client=new nusoap_client("http://localhost/webservice /webservices.php?wsdl");
          $client->setCredentials("webadmin","****");

           $err = $client->getError();
          if ($err) {

               echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';

            }

            $result = $client->call('test', array('id' => '1'));
            print_r($result);

如果您从PHP使用Web服务没问题,但在其他语言中存在兼容性问题

点赞