Read soap:Body from soap response in PHP - php

I have a soap response with this structure in PHP:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:srv="http://srv.soap.factura.sit.mx.com">
<soap:Body>
<srv:responseXMLT>
<return><tfd:ValorXML version="1.0" Key="000XY 212XH" FechaResponse="2014-05-14T14:37:45"/>
</return>
</srv:timbraCFDIXMLTestResponse>
I want to read the data inside of return and save each value in a database, but how can I read the value of .??
Thanks for all!!

Related

send request to wsdl file and get response using php

I searched a lot for this part but I found many issues so I confused between them
this is wsdl file
$wsdl = 'http://url.com/service.wsdl';
And below is the SOAP definition. How can I send request and get the response using php file
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ent="http://enterprise.olp.sadad.com/Infrastructure/EnterpriseContext" xmlns:ns="http://olp.sadad.com/sadadpaymentmanagement/service/sadadpaymentmanager/intf/1">
<soap:Header>
<ent:enterpriseContext>
<ent:contextInfo>
<ent:ProcessContextId>--</ent:ProcessContextId>
<ent:businessContextId>CO</ent:businessContextId>
<ent:applicationContextId>3</ent:applicationContextId>
</ent:contextInfo>
<ent:requestOriginator>
<ent:requesterCode>NCBK</ent:requesterCode>
<ent:machineIPAddress>00.00.00.00</ent:machineIPAddress>
<ent:userPrincipleName>NCB</ent:userPrincipleName>
<ent:requestedTimestamp>2015-10-01T05:53:04</ent:requestedTimestamp>
<ent:channelId>1</ent:channelId>
</ent:requestOriginator>
</ent:enterpriseContext>
</soap:Header>
<soap:Body>
<ns:InitiatePaymentDetails>
<InitiatePaymentDetailsRequest>
<transactionAmount>50</transactionAmount>
<olpIdAlias>abcd</olpIdAlias>
<merchantRefNum>1238688</merchantRefNum>
<merchants>
<merchantId>2854</merchantId>
<merchantRefNum>1238688</merchantRefNum>
<paymentAmount>50</paymentAmount>
<paymentCurrency>SAR</paymentCurrency>
<merchantType>1</merchantType>
</merchants>
<dynamicMerchantLandingURL>https://url.com/dummynow/success</dynamicMerchantLandingURL>
<dynamicMerchantFailureUrl>https://url.com/dummynow/failure</dynamicMerchantFailureUrl>
<merchantId>2854</merchantId>
</InitiatePaymentDetailsRequest>
</ns:InitiatePaymentDetails>
</soap:Body>
</soap:Envelope>

How to make proper SOAP request using PHP SoapClient when we see an example

I want to receive data using method GetCruise
How to do that in php using SoapClient, of course i know all URLs and I've got PartnerName, Password and AgencyCode
especially i need to know how to construct proper header of envelope using SoapClient::__setSoapHeaders
GetCruise
Call:
Proxy.Availability.GetCruise(“FO11060119”);
Parameters:
CruiseCode - the cruise code to be returned
Returns:
a fully described cruise (including itinerary and segments of an itinerary).
Example of soap envelope:
(headers must contain agency data - name paswword etc. i've got it)
SOAPAction: "http://schemas.costacrociere.com/WebAffiliation/GetCruise"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<Agency xmlns="http://schemas.costacrociere.com/WebAffiliation">
<Code>1111</Code>
<Culture />
</Agency>
<Partner xmlns="http://schemas.costacrociere.com/WebAffiliation">
<Name>AAAA</Name>
<Password>XXXX</Password>
</Partner></soap:Header>
<soap:Body>
<GetCruise xmlns="http://schemas.costacrociere.com/WebAffiliation">
<CruiseCode>FO11060119</CruiseCode>
</GetCruise>
</soap:Body>
</soap:Envelope>

getting pure xml detail from soap xml response

i have a .net service i am consuming from php and the result comes in the format below.
i wish to have only the contents without the soap:envelope.
How do i achieve this?
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><VAccResponse xmlns="http://apps.hbng.com/"><VAccResult><VAccountSummary><Id>C0000005</Id><AccountNo>5100000014</AccountNo><AccountName>xyz HOSPITAL LTD</AccountName><SchemeCode>abc</SchemeCode><SchemeDescription>abc records</SchemeDescription><Balance>6627282</Balance><CurrencyCode>DOLLARS</CurrencyCode><AccountManagerId>F05</AccountManagerId><Debit>0</Debit><Credit>0</Credit><Tran>NO TRANSACTION DONE</Tran></VAccountSummary></VAccResult></VAccResponse></soap:Body></soap:Envelope>
How do i get the xml result without the soap:body, soap envelope etc...

soap api with betfair

It's my first time using the SOAP API by BetFair I have created one XML file and one file that will call that file. I am not understanding how can I call this and get an output. I have created the XML file below:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<login xmlns="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<request>
<locationId xmlns="">0</locationId>
<username xmlns="">usrname</username>
<password xmlns="">password</password>
<productId xmlns="">18</productId>
<vendorSoftwareId xmlns="">0</vendorSoftwareId>
</request>
</login>
</soap:Body>
</soap:Envelope>
Now to call this file I have also created one php file to do this.
BetFair has given this link for the login api: https://api.betfair.com/global/v3/BFGlobalService.wsdl
<?php
$get_data = file_get_contents("http://pixelonsell.com/dev2/betfair/login.xml");
$b = html_entity_decode($get_data);
$data= urlencode($b);
print_r($data);
$client = new SoapClient("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
$result = $client->LoginReq($data);
print_r($result);
?>
I don't know why it's not working; can you help me out with this? Thank you in advance.
I would avoid using a dedicated SOAP library; in my experience they often don't work because of inconsistencies in the ways different servers implement the SOAP specification. Use a simple HTTP/HTTPS library instead, with the following headers
SOAPAction: urn:login
Content-Length: #{myContentLength}
Content-Type: text/xml
User-Agent: #{myUserAgent}
and the following payload (assuming you're using the Free API):
<SOAP-ENV:Envelope xmlns:SOAP-ENC="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">
<SOAP-ENV:Body>
<m:login xmlns:m="https://api.betfair.com/global/v3/BFGlobalService">
<m:request>
<username>#{myUsername}</username>
<password>#{myPassword}</password>
<locationId>0</locationId>
<vendorSoftwareId>0</vendorSoftwareId>
<productId>82</productId>
</m:request>
</m:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It looks to me like you're using the wrong namespace for the login element; should be 'https://api.betfair.com/..' not 'http://www.betfair.com/..'.
Good luck.

PHP : soapCall with complex arguments

I'm trying to set up a SOAP connexion between a supplier and I in order to synchronize data between our databases.
I've managed to connect him with a simple soapCall threw that php lines ($service is the name of the Soap function I'm reaching, and $data is an associative array that contains my variables) :
$request = new SoapClient($client, array('soap_version' => SOAP_1_1));
$response = $request->$service($data);
That lines work if my XML scheme of variables has no collections like in this example :
<?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>
<ServiceITryToReach xmlns="https://mysuplier:65100/">
<Login>login</Login>
<Password>pass</Password>
<Variables>
<Variable1>data</Variable1>
<Variable2>data</Variable2>
</Variables>
</ServiceITryToReach>
</soap:Body>
</soap:Envelope>
In the example above, my associative array that contains my variables will be :
array('Login'=>'login','Password'=>'pass','Variables'=>array('Variable1'=>'data','Variable2'=>'data'));
But, if my XML scheme contains collections of variables of same type, how can I represent it with an associative array in PHP ?
<?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>
<ServiceITryToReach xmlns="https://mysuplier:65100/">
<Login>login</Login>
<Password>pass</Password>
<Variables>
<Variable>
<data>data</data>
</Variable>
<Variable>
<data>data</data>
</Variable>
<Variable>
<data>data</data>
</Variable>
</Variables>
</ServiceITryToReach>
</soap:Body>
</soap:Envelope>
In conclusion, I'm looking for another simple way to request my supplier with multiple variables. The best would be to have a direct XML input in my soapCall method instead of an associative array.
An idea ?
Thanks,
Nico

Categories