在PHP中传递多维数组给soapcomplextype



我正在从邮件服务器中取出一些邮件。有一个函数应该拉这些电子邮件,并返回一个多维数组。我使用这个数组在客户端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行XML解析SOAP负载错误:格式不正确(无效令牌)

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服务没有问题,但在其他语言中存在兼容性问题

相关内容

  • 没有找到相关文章

最新更新