doutu3352 2011-09-20 09:43
浏览 115

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

I am pulling some emails from my mail server. There is a function should pull these emails and return a multidimensional array. I use this array in client web server to do the job for me. I don't know how to pass this array to the soap complexType. I wrote the following code:

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

and on the client, I wrote:

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

I got this error:

Constructor error

XML error parsing SOAP payload on line 1: Not well-formed (invalid token)

  • 写回答

1条回答 默认 最新

  • dongyunwei8596 2012-11-04 04:08
    关注

    NuSOAP support return multidimensional array (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

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

    if you consume the webservices from PHP no problem, but in other languages there are compatibility problems

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数