2013-11-01 2 views
1

API를 호출하려고합니다. 필요한 XML은 다음과 같습니다.SOAP 호출에 같은 이름의 여러 노드가 있습니다.

<SOAP-ENV:Envelope xmlns:ns1="http://www.webserviceX.NET/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
<SOAP-ENV:Body> 
<ns1:ConversionRate/> 
    <param1> 
     <MessageTitle>Some Title</MessageTitle> 
     <Images> 
      <Image>http://3.bp.blogspot.com/-gzGWCfqJr_k/T-B7L0wlwSI/AAAAAAAADkw/C7sznAKVktc/s1600/rose_flower_screensaver-234027-1240456558.jpeg</Image> 
      <Image>http://img.ehowcdn.com/article-new-thumbnail/ehow/images/a07/tv/vu/object-property-names-array-php-800x800.jpg</Image> 
     </Images> 
    </param1> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

태그에 여러 이미지를 전달하고 싶습니다. 하지만 한 항목 만 전달할 수 있습니다. PHP에서 다중 차원 배열은 동일한 키를 지원하지 않습니다. 내 PHP 코드

$client = new SoapClient('http://www.webservicex.com/CurrencyConvertor.asmx?wsdl',  array( 'trace'  => true, 'exceptions' => true,'soap_version' => SOAP_1_1)); 
    try { 

     $data_params = new stdClass(); 
     $imgs = new stdClass(); 

     $img1 = 'http://3.bp.blogspot.com/-gzGWCfqJr_k/T-B7L0wlwSI/AAAAAAAADkw/C7sznAKVktc/s1600/rose_flower_screensaver-234027-1240456558.jpeg'; 
     $img2 = 'http://img.ehowcdn.com/article-new-thumbnail/ehow/images/a07/tv/vu/object-property-names-array-php-800x800.jpg'; 

     $imgs->Image = $img1; 

     $data_params->MessageTitle    = 'Some Title'; 
     $data_params->Images      =  $imgs;   

     $params = array( 'Id' => '187', 
        'Data'=>$data_params); 

     $result = $client->__soapCall('ConversionRate',$params); 
     echo $client->__getLastRequest(); 
    }catch(SoapFault $exception) 
    { 
      var_dump($exception); 
      echo $client->__getLastRequest(); 
    } 
+0

존재하지 않습니다 이러한 매개 변수 이미지 URL을 어디서나 - 내 대답 참조 : http://stackoverflow.com/a/19745107/367456 그냥 작동합니다. – hakre

답변

0

는 유형을 복제, 당신은 절대적으로 뭔가를 혼동해야합니다

<Images> 
    <Image> 
    <item>your Image<item> 
    </Image> 
    <Image> 
    <item>your 2nd Image<item> 
    </Image> 
    </Images> 
0

, 문제의 CurrencyConvertor의 웹 서비스의 ConversionRate 방법은 잘 작동처럼 어떤 일을 시도하고 중복 된 매개 변수 이름이 없습니다 하지만 이미지 URL이 아닌 문자열입니다. 여기

class stdClass#2 (1) { 
    public $ConversionRateResult => 
    double(1.3488) 
} 

이 작업 코드 : 여기

이 (ConversionRate EUR에서 USD로) 작업 코드의 출력 당신은 여기에 웹 서비스를 혼동한다

<?php 
/** 
* Multiple Nodes with same Name in SOAP Call 
* @link http://stackoverflow.com/q/19727338/367456 
*/ 

$wsdl = 'http://www.webservicex.com/CurrencyConvertor.asmx?wsdl'; 
$options = array(
    'trace'  => true, 
    'exceptions' => true, 
    'soap_version' => SOAP_1_1, 
); 

$client = new SoapClient($wsdl, $options); 

$params = array(
    'FromCurrency' => 'EUR', 
    'ToCurrency' => 'USD', 
); 

var_dump(
    $client->ConversionRate($params) 
); 
관련 문제