Ошибка PHP при использовании SOAP - PullRequest
0 голосов
/ 19 октября 2011

В настоящее время у меня возникает ошибка при подключении к веб-сервису.Вот мой 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 = "cutomer@email.com";
$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>.

Спасибо за любую помощь.

1 Ответ

0 голосов
/ 19 октября 2011
    $simpleresult = $result->$methodResultName;

Убедитесь, что эта строка действительно что-то производит, и что $methodResultName действительно существует в вашем $result объекте.если он не существует, PHP просто назначит null для $simpleresult, который вы затем попытаетесь передать в DOM с помощью $simpleresult->any, который также будет получен null.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...