2011-09-20 97 views
4

我正在從郵件服務器中拖出一些電子郵件。有一個函數應該拉這些電子郵件並返回一個多維數組。我在客戶端Web服務器中使用這個數組來爲我完成這項工作。我不知道如何將這個數組傳遞給soap complexType。我寫了下面的代碼:將多維數組傳遞給soap complexType中的PHP

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

我得到這個錯誤:

構造錯誤

XML錯誤分析在線SOAP有效載荷1:格式不正確(無效令牌)

+0

你有沒有解決這個問題?我試圖做同樣的事情,將數組傳遞到請求輸入,但是當我使用生成的WDSL時,它只是不會讀取數組(僅當我沒有WDSL連接時) – Horse

回答

2

NuSOAP支持返回多維數組(XSD:陣列)

  $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服務沒有問題,但在其他語言中也有兼容性問題