2011-10-18 19 views
0

Webサービスに接続する際に現在エラーが発生しています。ここに私のPHPスクリプトは次のとおりです。SOAPを使用するとPHPエラーが発生する

<?php 

//initialise test SOAP client 
$wdsl = myaddress; 
$soapClient = new SoapClient("$wdsl"); 
$apiKey = myapikey; 
$clientID = myclientid; 

//assign customer information that would normally be pulled from database 
$strVendorTxCode = "thepartyshack-0000000001-0000000001"; 
$strEmail = "[email protected]"; 
$strPhone = "07901888408"; 
$strDelivery = "ZZRML_NDSD"; 

//Build the XML string that will be sent to Smiffys 
$strXML = $strXML . "<?xml version='1.0' encoding='Windows-1252'?><Order>"; 
//Customer Reference Number. 
$strXML = $strXML . "<YourOrderNumber>" . $strVendorTXCode . "</YourOrderNumber>"; 
//More XML That does not change 
$strXML = $strXML . "<Recipient>"; 
//Add in customer email 
$strXML = $strXML . "<Email>" . $strEmail . "</Email>"; 
//Add in our customer telepone number 
$strXML = $strXML . "<Telephone>" . $strPhone . "</Telephone>"; 
//Add in customer name 
$strXML = $strXML . "<Recipient>" . "Mrs Customer" . "</Recipient>"; 
//Add in customer address line 
$strXML = $strXML . "<AddressLine>" . "1 High Street" . "</AddressLine>"; 
//Add in customer city 
$strXML = $strXML . "<City>" . "Anyplace" . "</City>"; 
//Add in customer postcode 
$strXML = $strXML . "<PostCode>" . "AA1 1AA" . "</PostCode>"; 
//Add in customer county 
$strXML = $strXML . "<County>" . "Anywhere" ."</County>"; 
//Add in customer country 
$strXML = $strXML . "<CountryCode>" . "GB" . "</CountryCode>"; 
//Another line not to be changed 
$strXML = $strXML . "</Recipient>"; 
//Add delivery 
$strXML = $strXML . "<DeliveryCode>" . $strDelivery . "</DeliveryCode>"; 
//Another line not to be changed 
$strXML = $strXML . "<Lines>"; 
//Add in the basket in the form of 'line' 
$strXML = $strXML . "<Line><ProductCode>25402</ProductCode><ProductQuantity>1</ProductQuantity></Line>"; 
//Close all remaing tags XML done. 
$strXML = $strXML . "</Lines></Order>"; 

//Make the SOAP request and get the response 
$stockParameters = array('apiKey'=>$apiKey,'clientID'=>$clientID,'orderXml'=>$strXML); 
$SubmitOrder=GetXml($soapClient,'SubmitOrder',$stockParameters,'Order'); 
$ResultSets = array(array('name' =>'SubmitOrder','ResultSet' => $SubmitOrder)); 
$myresults = array(); 
foreach($ResultSets as $result){ printTableRecords($result,10); }; 

function GetXml($soapClient,$method,$parameters,$resultSetTag){ 
    try { 
     $methodResultName = $method."Result"; 
     $result = $soapClient->$method($parameters); 
     $simpleresult = $result->$methodResultName; 
    return getElementsFromResult($resultSetTag,$simpleresult); 
    }catch (SoapFault $exception) { 
     echo $exception; 
    } 
} 
function getElementsFromResult($elementName,$simpleresult){ 
    $dom = new DOMDocument; 
    $dom->preserveWhiteSpace = FALSE; 
    if($simpleresult==null) { 
     echo 'null'; 
     return null; 
    }else{ 
     $dom->loadXML($simpleresult->any); 
     return $dom->getElementsByTagName($elementName); 
    } 
} 
function printTableRecords($xmlNodeList,$count) { 
    foreach ($xmlNodeList['ResultSet'] as $node) { 
     $myvar = 0; 
     foreach($node->childNodes as $childNode){ 
      $entity = htmlentities($childNode->nodeValue); 
      $myresults[$myvar] = $entity; 
      $myvar ++; 
     } 
    } 
    echo $myresults[1]; 
} 
?> 

私はこのエラーが発生した上記の要求を行うとき、私はしかし、サイトの他の領域で正常に近く、同一のSOAPリクエストを使用します。

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in /home/content/89/8236789/html/test.php on line 72 

私は要求しています回答

<OrderResultBase> 
    <ReturnCode>Successful</ReturnCode> 
    <YourOrderNumber>thepartyshack-0000000001-0000000001</YourOrderNumber> 
    <Lines> 
     <Line> 
      <ProductCode>25402</ProductCode> 
      <ProductQuantity>1</ProductQuantity> 
      <Status>Confirmed</Status> 
     </Line> 
    </Lines> 
    <DeliveryCode>ZZRML_NDSD</DeliveryCode> 
</OrderResultBase> 

私が検索する必要がある行は、<ReturnCode>の内容です。

ありがとうございました。

答えて

0
$simpleresult = $result->$methodResultName; 

この行は実際に何かを生産し、$methodResultName実際にあなたの$resultオブジェクト内に存在することであることを確認してください。存在しない場合、PHPはnull$simpleresultに割り当て、$simpleresult->anyでDOMにフィードしようとすると、nullとなります。

+0

私は非常にPHPの初心者です。ソリューションの実装方法を教えてください。 – mjohnston

+0

すべてのデバッギング文を叩いてください。 ... –

+0

少しデバッグしています。私は、DOMの '$ simpleresult-> any'に' simpleresult'の値を入力する時点で、 ' stdClassオブジェクト([ProductCode] => 25402 [ProductQuantity] => 1 [Status] => Confirmed))stdClassオブジェクト([ReturnCode] =>成功[YourOrderNumber] => [Lines] => [DeliveryCode] => ZZRML_NDSD) ' – mjohnston

関連する問題