2011-09-20 2 views
4

내 메일 서버에서 일부 이메일을 가져옵니다. 이 전자 메일을 가져 와서 다차원 배열을 반환해야하는 함수가 있습니다. 나는이 배열을 클라이언트 웹 서버에서 사용하여 나를 위해 일한다. 이 배열을 soap complexType에 전달하는 방법을 모르겠습니다. 다음 코드 작성 :PHP에서 complexType을 SOAP에 다차원 배열로 전달

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

나는이 오류가 발생했습니다 :

생성자 오류

라인에 SOAP 페이로드를 구문 분석

XML 오류 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에서 웹 서비스 문제 없음을 소비하는 경우,하지만 다른 언어

관련 문제