I want to transform my SOAP request from key-value format to another:
<SOAP-ENV:Header>
<ns2:AUTH>
<item>
<key>username</key>
<value>testuser</value>
</item>
<item>
<key>password</key>
<value>xxxxx</value>
</item>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is what I want:
<SOAP-ENV:Header>
<ns2:AUTH>
<username>testuser</username>
<password>xxxxx</password>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig>
<partner_id>1</partner_id>
</ns1:getProductConfig>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is my PHP code where I create a new SoapClient object:
$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;
PS: Currently, It's non wsdl style but I'm thinking about to change to use wsdl too.
This may sound crazy, but I just fixed this by using WSDL instead.
It is much easier. WSDL file will determine both SOAP request and response.
Related
How do I read this soap response and echo the values of subid and points.
Here is the response
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:zuku">
<SOAP-ENV:Body>
<ns1:showloyaltypointsResponse xmlns:ns1="http://tempuri.org">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:subpoints[1]">
<item xsi:type="tns:subpoints">
<subid xsi:type="xsd:integer">618341</subid>
<points xsi:type="xsd:string">0</points>
</item>
</return>
</ns1:showloyaltypointsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is my php code
$result = $client ->call('showloyaltypoints',array("subid" =>$subid,"username" =>"$username", "password" =>"$password"));
echo $client->response;
I found out the solution by converting it to an array first.
https://stackoverflow.com/a/42311833/7042343
Hi I want to get value from given XML using simple_xml_string but its not working. XML is given below:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
<eb:From><eb:PartyId eb:type="urn:x12.org.IO5:01">webservices.sabre.com</eb:PartyId></eb:From>
<eb:To><eb:PartyId eb:type="urn:x12.org.IO5:01">info#gandakiintl.com</eb:PartyId></eb:To>
<eb:CPAId>T198</eb:CPAId>
<eb:ConversationId>111#gandakiintl.com</eb:ConversationId>
<eb:Service eb:type="SabreXML">Enhanced Air Book Request</eb:Service>
<eb:Action>ErrorRS</eb:Action>
<eb:MessageData>
<eb:MessageId>1522435489615361760</eb:MessageId>
<eb:Timestamp>2017-01-11T13:36:01</eb:Timestamp>
<eb:RefToMessageId>mid:11110info#gandakiintl.com</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">
Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0
</wsse:BinarySecurityToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client.InvalidSecurityToken</faultcode>
<faultstring>Invalid or Expired binary security token: Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0</faultstring>
<detail>
<StackTrace>
com.sabre.universalservices.base.session.SessionException: errors.session.USG_INVALID_SECURITY_TOKEN
</StackTrace>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
From above xml I want to get faultCode node value But I am not able to get. Please help. I tried doing it but its not working.
$feed = simplexml_load_string($response);
$a = $feed->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($a->Fault->children('http://schemas.xmlsoap.org/soap/envelope/'));
Edited:
Output I get is: Node no longer exists. But I want to get "soap-env:Client.InvalidSecurityToken" value.
I am using one payment gateway that return response as xml and I am trying to convert to json buy its not converting. I have tried that simplexamlloadfile , simplexmlsting function and etc.
But its not working.
Code :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns2:SingleVaultResponse xmlns:ns2="http://www.paygate.co.za/PayHOST">
<ns2:LookUpVaultResponse>
<ns2:Status>
<ns2:StatusName>Completed</ns2:StatusName>
<ns2:PayVaultData>
<ns2:name>cardNumber</ns2:name>
<ns2:value>411111xxxxx1111</ns2:value>
</ns2:PayVaultData>
<ns2:PayVaultData>
<ns2:name>expDate</ns2:name>
<ns2:value>012025</ns2:value>
</ns2:PayVaultData>
<ns2:PaymentType>
<ns2:Method>CC</ns2:Method>
<ns2:Detail>Visa</ns2:Detail>
</ns2:PaymentType>
</ns2:Status>
</ns2:LookUpVaultResponse>
</ns2:SingleVaultResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Try this:
$string2 = 'your xml sting';
$doc = new DOMDocument;
$doc->loadXML($string2);
echo "status => ".$doc->getElementsByTagName('Status')->item(0)->nodeValue;
I want to call a function of a web service in my project developed by PHP. This is my code:
$wsdl="http://x.x.x.x:8090/charge/services/Amount?wsdl";
$client = new SoapClient($wsdl) or die("Error");
$chargeAmountArray = array('UserIdentifier' => $number ,
'data' => array(
'description' => array("Channel=test|".$Origin),
'currency' => NULL,
'code' => $code),
'refrence' => $refcode);
$header = new SoapHeader('servicekey', $servicekey);
$client->__setSoapHeaders($header);
$res = $client->__call('chargeAmount',$chargeAmountArray);
return $res->return;
I have seen my xml code with tcpdump and it is like:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.csapi.org/schema/parlayx/payment/amount_charging/v4_0/local" xmlns:ns2="servicekey">
<SOAP-ENV:Header>
<ns2:e0ce5ed56d7c4d60/>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:chargeAmount/>
<param1>
<item>
<key>description</key>
<value>yChannel=test|30733</value>
</item>
<item>
<key>currency</key>
<value/>
</item>
<item>
<key>code</key>
<value>MOBDY</value>
</item>
</param1>
<param2>1PN1mROoZop2hAy</param2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you see the UserIdentifier is not passed and the refrence parameter has no name in the XML.
I see a few errors here.
The constructor signature for the SoapHeader class shows the first parameter is a namespace declaration, which it doesn't appear you are setting.
Also, SoapClient::__call() is deprecated; instead you should call the method directly:
$res = $client->chargeAmount($chargeAmountArray);
SoapClient::__call() expects parameters in an array with key "parameters", which you are not providing.
Finally, you should be doing some error checking with try/catch in case the connection can't be made for whatever reason.
I got an XML response as
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.*********.in">
<SOAP-ENV:Body>
<ns1:LoginResponse>
<return>
<SessionID>3AC46E3F62</SessionID>
<ResponseCode>0</ResponseCode>
<ResponseMessage>Successful</ResponseMessage>
</return>
</ns1:LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I parse the SessionID and ResponseCode from this xml using PHP.Im unable to do this.Please suggest some methods to do this.
Check this : How can I get and process a response from a PHP API and apply print_r(htmlentities($xmldata->asXML())); to your XML response
and this too : soap:Envelope SOAP-ENV:Envelope PHP
the responses from there maybe will help you , of course you may code yourself cause is very easy
Check this code too is already working example (very close to your problem):
<?php
$a ='<soap-env:envelope xmlns:ns1="http://v3.core.com.productserve.com/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<ns1:getproductlistresponse>
<oproduct>
<iid>113133802</iid>
<icategoryid>270</icategoryid>
<imerchantid>1547</imerchantid>
<iadult>0</iadult>
<sname>The Ashes / 5th Test - England v Australia - Day 1</sname>
<sawdeeplink>http://www.awin1.com/pclick.php?p=113133802&a=111402&m=1547&platform=cs</sawdeeplink>
<sawthumburl>http://images.productserve.com/thumb/1547/113133802.jpg</sawthumburl>
<fprice>119.99</fprice>
</oproduct>
</ns1:getproductlistresponse>
</soap-env:body>
</soap-env:envelope>';
$xml = simplexml_load_string($a);
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['soap-env']);
$getproductlistresponse = $soap->body->children($ns['ns1']);
foreach ($getproductlistresponse->children() as $item)
{
//This example just accesses the iid node but the others are all available.
echo (string) $item->iid . '<br />';
}
?>