php parse soap response with ns - soap

i have the following soap response
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns0:READResponse xmlns:ns0="/PELTT01">
<ns0:st_flag>0</ns0:st_flag>
<ns0:st_title></ns0:st_title>
<ns0:pod_date></ns0:pod_date>
<ns0:pod_time></ns0:pod_time>
<ns0:pod_name></ns0:pod_name>
<ns0:web_status>
<ns0:web_date>date1</ns0:web_date>
<ns0:web_time>time1</ns0:web_time>
<ns0:web_station>station1</ns0:web_station>
<ns0:web_status_title>title1</ns0:web_status_title>
</ns0:web_status>
<ns0:web_status>
<ns0:web_date>date2</ns0:web_date>
<ns0:web_time>time2</ns0:web_time>
<ns0:web_station>station2</ns0:web_station>
<ns0:web_status_title>title2</ns0:web_status_title>
</ns0:web_status>
...
...
<ns0:web_status_counter>5</ns0:web_status_counter>
</ns0:READResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i have try to get web_status nodes but everything fails
Try 1
$dom = new DOMDocument();
$dom->load($xml_response);
$web_status = $dom->getElementsByTagName('web_status');
Try 2
$dom = new DOMDocument();
$dom->load($xml_response);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("ns0", "/PELTT01");
$web_status = $xpath->query('//ns0:web_status');
Can anyone help me parse this soap response
Any help appreciated

If I understand you correctly, you're looking for something close to your Try 2:
$dom->loadXML($xml_response);#note: NOT just "load"
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("ns0", "/PELTT01");
$web_status = $xpath->query('//ns0:web_status');
foreach ($web_status as $wb)
{
$cn = $wb->childNodes;
foreach ($cn as $c){
echo trim($c->textContent);
}
}
Output:
date1
time1
station1
title1
date2
time2
station2
title2

Related

Authentication Issue with eBatNS Trading API trying to get SessionID

I'm trying to get a session ID using the eBatNS SOAP API.
The function which makes the call is pretty simple, but always returns an Authentication error. You can see the function below
public function get_ebay_session()
{
error_reporting(0);
$ruName = "Forward_Thinker-ForwardT-57fe-4-rybapdi";
$sessionID = "";
//Connect to eBay and get a list of all products
require_once 'eBay/EbatNs/EbatNs_ServiceProxy.php';
require_once 'eBay/EbatNs/GetSessionIDRequestType.php';
require_once 'eBay/EbatNs/EbatNs_Logger.php';
//Get a SessionID
$session = new EbatNs_Session('eBay/config/ebay.config.php');
print_r($session);
echo "<hr>";
$cs = new EbatNs_ServiceProxy($session);
$cs->attachLogger(new EbatNs_Logger(false, 'stdout', true, false));
print_r($cs);
echo "<hr>";
$req = new GetSessionIDRequestType();
$req->setRuName($ruName);
print_r($req);
echo "<hr>";
$result = $cs->GetSessionID($req);
$sessionID = $result->SessionID;
print_r($result);
echo "<hr>";
session_start();
$_SESSION['eBaySessionID'] = $sessionID;
$return = $ruName."\n".$sessionID;
$this->set(compact('return'));
}
As you can see I have attached a logger. The logger shows that this is the request being made.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns="urn:ebay:apis:eBLBaseComponents" ><soap:Header><RequesterCredentials><eBayAuthToken>AgAAAA**AQAAAA**aAAAAA**wS7oUQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wHloSkD5aGog+dj6x9nY+seQ**It4BAA**AAMAAA**CB7yrHTyG3kQbA6KOwf0ZO2MqyPs/Dfn5u5r8ZDVGeWNvB</eBayAuthToken><Credentials><AppId>ForwardT-57fe-41ea-b90e-52fd0b541b88</AppId><DevId>5eefba38-e226-4876-9ada-d8743f571aeb</DevId><AuthCert>b57984cb-ba9c-430c-a8fc-c08f9ac46e75</AuthCert></Credentials></RequesterCredentials></soap:Header><soap:Body><GetSessionIDRequest><Version><![CDATA[815]]></Version><RuName><![CDATA[Forward_Thinker-ForwardT-57fe-4-rybapdi]]></RuName></GetSessionIDRequest></soap:Body></soap:Envelope>
And that this is the response being returned:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:FailedCheck</faultcode>
<faultstring>Authorisation token is invalid.</faultstring>
<faultactor>http://www.ebay.com/ws/websvc/eBayAPI</faultactor>
<detail>
<FaultDetail>
<ErrorCode>931</ErrorCode>
<Severity>Error</Severity>
<DetailedMessage>Validation of the authentication token in API request failed.</DetailedMessage>
</FaultDetail>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
My ebay.config.php file has all the correct keys and, as far as I can tell, all of the correct information. Does anyone have any tips for resolution?
Danny
This issue was caused by the eBatNS API sending a token from a previous request in the request to get a new token. This isn't supported by ebay.
This is resolved by setting the token mode on the session to 0 or false.
$session->setTokenMode(0)

Accessing SOAP services with Google Apps Script

I'm trying to use Google Apps Scripts to call a SOAP service call, and I've been trying to tinker with a number of ways to get a response; however, I keep getting an error. I've defaulted to trying to send an exact copy of a message stored in my spreadsheet that I know works through another service... still no luck. Here's the Apps Script Code:
function getVesselSummaryXMLStringFromName() {
var wsdl = SoapService.wsdl("http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL");
Logger.log(wsdl.getServiceNames());
var uscgService = wsdl.getPSIXData();
var sheet = SpreadsheetApp.getActiveSheet();
//Get working SOAP message
var envelope = sheet.getRange("D1:D1").getValues();
Logger.log(envelope);
var result = uscgService.getenvelope;
Logger.log(result);
}
The SOAP message I'm sending that works through http://www.soapclient.com/soapclient is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://cgmix.uscg.mil" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><SOAP-ENV:Body><tns:getVesselSummaryXMLString xmlns:tns="http://cgmix.uscg.mil"><tns:VesselID></tns:VesselID><tns:VesselID></tns:VesselID><tns:VesselName>Atlantic Salvor</tns:VesselName><tns:VesselName></tns:VesselName><tns:CallSign></tns:CallSign><tns:CallSign></tns:CallSign><tns:VIN></tns:VIN><tns:VIN></tns:VIN><tns:HullNum></tns:HullNum><tns:HullNum></tns:HullNum><tns:Flag></tns:Flag><tns:Flag></tns:Flag><tns:Service></tns:Service><tns:Service></tns:Service><tns:BuildYear></tns:BuildYear><tns:BuildYear></tns:BuildYear></tns:getVesselSummaryXMLString></SOAP-ENV:Body></SOAP-ENV:Envelope>
The following code returns an answer, so maybe you can help.
...
var url = 'http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL';
var wsdl = SoapService.wsdl(url);
var servicePSIXData = wsdl.getPSIXData();
var params = Xml.element('getVesselSummaryXMLString', [
Xml.attribute('xmlns', 'http://cgmix.uscg.mil'),
Xml.element('VesselID', ['']),
Xml.element('VesselName', ['Atlantic Salvor']),
Xml.element('CallSign', ['']),
Xml.element('VIN', ['']),
Xml.element('HullNum', ['']),
Xml.element('Flag', ['']),
Xml.element('Service', ['']),
Xml.element('BuildYear', [''])
]);
var result = servicePSIXData.getVesselSummaryXMLString(params);
Logger.log(result.toXmlString());
...
UPDATE
Both Xml Services and Soap Services are considered deprecated.

How to send XML as String to Soap Action?

I have Soap Action
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<From_Iphone xmlns="http://tempuri.org/">
<MessageText>string</MessageText>
<user_id>int</user_id>
<patientID>int</patientID>
<ReplyToMsgId>int</ReplyToMsgId>
<UserContacts>string</UserContacts>
</From_Iphone>
</soap:Body>
</soap:Envelope>
in this i would like to send the
MessageText =#"Testing";
patientID= 10;
user_id= 20;
ReplyToMsgId=1;
UserContacts = #"< Contacts > < Contact >< id > 5 < /id > < name > Kiran< /name > < gr_id >11 < /gr_id> < /Contact> < Contact>< id>8< /id> < name>najeer< /name>< gr_id>25< /gr_id>< /Contact>< /Contacts>";
I am passing the UserContacts as string but i am not able to hit the server. Please give me a solution for passing an xml as String..
Thank You...
You have to use tag for this.
In tag u have to put Your xmlstring.
The string between the will not be parsed. I think Your problem will be solved.
http://www.w3schools.com/xml/xml_cdata.asp
fallow the above link it will help You

xpath soap namespace grabbing items

I am feeling like i am doing something really not correct.
When doing a soap they return me with an xml which may or may not contain an error.
I would like to check if the error exists if not read the values.
somehow, I can't grab it directly :(
Below is a sample return of something with results and one which gives an error (name not found)
<?xml version="1.0" encoding="utf-8"?>
<soapEnvelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<envHeader xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsaAction>http://www.rechtspraak.nl/namespaces/ccr01/searchPersonResponse</wsaAction>
<wsaMessageID>urn:uuid:b75d2932-5687-4871-9d07-3b74b084978a</wsaMessageID>
<wsaRelatesTo>urn:uuid:9112d870-248d-4d07-acd0-d88e4a48d547</wsaRelatesTo>
<wsaTo>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsaTo>
<wsseSecurity>
<wsuTimestamp wsu:Id="Timestamp-061df7b5-32a2-4021-852d-2df98953e076">
<wsuCreated>2011-05-27T12:11:45Z</wsuCreated>
<wsuExpires>2011-05-27T12:16:45Z</wsuExpires>
</wsuTimestamp>
</envHeader>
<soapBody>
<searchPersonResponse xmlns="http://www.rechtspraak.nl/namespaces/ccr01">
<searchPersonResult>
<CCR_WS xmlns="http://www.rechtspraak.nl/namespaces/ccr">
<curandus>
<ccn>1</ccn>
<cur_voornamen>Jan</cur_voornamen>
<cur_voorvoegsels>van</cur_voorvoegsels>
<cur_achternaam>Beek</cur_achternaam>
<geboorte_datum>1980-01-02</geboorte_datum>
<geboorte_plaats>Werkendam</geboorte_plaats>
</curandus>
</CCR_WS>
</searchPersonResult>
</searchPersonResponse>
</soapBody>
</soapEnvelope>
and the one without results
<?xml version="1.0" encoding="utf-8"?>
<soapEnvelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<envHeader xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<wsaAction>http://www.rechtspraak.nl/namespaces/ccr01/searchPersonResponse</wsaAction>
<wsaMessageID>urn:uuid:b75d2932-5687-4871-9d07-3b74b084978a</wsaMessageID>
<wsaRelatesTo>urn:uuid:9112d870-248d-4d07-acd0-d88e4a48d547</wsaRelatesTo>
<wsaTo>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsaTo>
<wsseSecurity>
<wsuTimestamp wsu:Id="Timestamp-061df7b5-32a2-4021-852d-2df98953e076">
<wsuCreated>2011-05-27T12:11:45Z</wsuCreated>
<wsuExpires>2011-05-27T12:16:45Z</wsuExpires>
</wsuTimestamp>
</envHeader>
<soapBody>
<searchPersonResponse xmlns="http://www.rechtspraak.nl/namespaces/ccr01">
<searchPersonResult>
<CCR_WS xmlns="http://www.rechtspraak.nl/namespaces/ccr">
<exceptie errorcode="1">No Results found.</exceptie>
</CCR_WS>
</searchPersonResult>
</searchPersonResponse>
</soapBody>
</soapEnvelope>
Here is my code to select the namespace, then check
$results = simplexml_load_string($response);
$results->registerXPathNamespace('ccr','http://www.rechtspraak.nl/namespaces/ccr');
$lijst = $results->xpath('//ccr:CCR_WS');
$errorcode = $lijst[0]->exceptie->attributes()->errorcode;
$error = $lijst[0]->exceptie;
if (isset($errorcode) AND $errorcode != "") {
// do things with the error code
} else {
$lijst = $results->xpath('//ccr01:searchPersonResult');
$cur = $lijst[0]->CCR_WS->curandus;
echo $cur->ccn."<BR>";
echo $cur->cur_voornamen."<BR>";
echo $cur->cur_voorvoegsels."<BR>";
echo $cur->cur_achternaam."<BR>";
echo $cur->geboorte_datum."<BR>";
echo $cur->geboorte_plaats."<BR>";
}
surely there is a better way of grabbing
$lijst[0]->exceptie->attributes()->errorcode
for example...
...Don't know if this is a "better way" to everyone, but here is a direct XPath expression to select the errorcode. You can make it shorter and less efficient by dropping steps and using // (in the beginning or in the middle). Attributes are selected with # (or with attribute:: axis if you prefer the longer syntax). If attribute (or the exceptie element) doesn't exist, nothing is returned.
/*/*/ccr01:searchPersonResponse/ccr01:searchPersonResult/ccr:CCR_WS/ccr:exceptie/#errorcode
Remember to register all the namespace prefixes that yo use in your XPath expression.

How to send raw xml to SOAP server using Zend_Soap_Client?

I'm traying to send a raw request to a SOAP server. The only way I found to do this is creating a redundant Zend_Soap_Client_Common in order to invoke _dorequest. Is really that necessary? Is there any other way to send raw xml to the server?
Here's the code:
$client = new Zend_Soap_Client('http://212.170.239.71/appservices/ws/FrontendService?wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'http://212.170.239.71/appservices/ws/FrontendService'
)
);
$location = 'http://212.170.239.71/appservices/ws/FrontendService';
$request = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<hb:getHotelValuedAvail xmlns:hb="http://axis.frontend.hydra.hotelbeds.com" xsi:type="xsd:anyType">
<HotelValuedAvailRQ echoToken="DummyEchoToken" sessionId="DummySessionId" xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRQ.xsd">
<Language>CAS</Language>
<Credentials>
<User>XXXXX</User>
<Password>XXXXX</Password>
</Credentials>
<PaginationData pageNumber="1"/>
<ExtraParamList>
<ExtendedData type="EXT_ORDER">
<Name>ORDER_CONTRACT_PRICE</Name>
<Value>ASC</Value>
</ExtendedData>
</ExtraParamList>
<CheckInDate date="20110809"/>
<CheckOutDate date="20110811"/>
<Destination code="LPA" type="SIMPLE">
<ZoneList>
<Zone code="20" type="SIMPLE"/>
</ZoneList>
</Destination>
<OccupancyList>
<HotelOccupancy>
<RoomCount>1</RoomCount>
<Occupancy>
<AdultCount>2</AdultCount>
<ChildCount>0</ChildCount>
</Occupancy>
</HotelOccupancy>
</OccupancyList>
</HotelValuedAvailRQ>
</hb:getHotelValuedAvail>
</soapenv:Body>
</soapenv:Envelope>';
$clientCommon = new Zend_Soap_Client_Common($client, 'http://212.170.239.71/appservices/ws/FrontendService?wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'http://212.170.239.71/appservices/ws/FrontendService'
));
$response = $client->_doRequest($clientCommon, $request, $location, 'getHotelValuedAvail', SOAP_1_1);
// With these two lines I've managed the call using "native" SoapClient
//$client = new SoapClient("http://212.170.239.71/appservices/ws/FrontendService?wsdl", array('trace'=>1));
//$response = $client->__doRequest($request, $location, 'getHotelValuedAvail', SOAP_1_1);
Thanks in advance.
Jorge