soap request and response in php LARAVEL - php

i am new to soap request and response in PHP ,i am working with recharge API.
API providers given me below XML(I Am using Arzoo API Providers).
<MobileRechargeRequest>
<Clientid>Given By Arzoo</Clientid>
<Clientpassword>Given By Arzoo</Clientpassword>
<ClientType>ArzooFWS1.1</ClientType>
<ServiceProvider>AIRTEL-TopUp</ServiceProvider>
<ServiceProviderId>1</ServiceProviderId>
<Rechrgeamount>100.0</Rechrgeamount>
<SubscriberID>9876543210</SubscriberID>
<PartnerReferenceId>123456</PartnerReferenceId>
</MobileRechargeRequest>
They said this is SOAP API, how can i send this request to their URL:-
http://demo.arzoo.com/ArzooWS/services/MobileRecharge?wsdl
using SOAP in PHP.
I tried like below code
$soapclient = new \SoapClient('http://demo.arzoo.com/ArzooWS/services/MobileRecharge?wsdl');
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('CountryName' => 'Spain', 'CityName' => 'Alicante');
$response = $soapclient->getMobileDetails('<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<getMobileDetails xmlns="http://demo.arzoo.com/ArzooWS/services/MobileRecharge">
<MobileRechargeRequest>
<Clientid>77743781</Clientid>
<Clientpassword>******</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<ServiceProvider>AIRTEL-TopUp</ServiceProvider>
<ServiceProviderId>1</ServiceProviderId>
<Rechrgeamount>100.0</Rechrgeamount>
<SubscriberID>9164995714</SubscriberID>
<PartnerReferenceId>123456</PartnerReferenceId>
</MobileRechargeRequest> </getMobileDetails> </soap:Body></soap:Envelope>');
var_dump($response);
I am not getting any response please help me , if i have error in SOAP XML request

Related

How to set wsa true and ws addressing true in pure php of soap webservice

$data2=[
"user_name"=>"****",
"password"=>"****",
"customer_num"=>"***",
"process_num"=>000,
];
$wsdl = "https://vbtestservice.vakifbank.com.tr/HesapHareketleri.OnlineEkstre/SOnlineEkstreServis.svc?singleWsdl";
$client =new SoapClient($wsdl,array("trace"=>true,"exceptions"=>0));
$a=$client->__soapCall('GetirDekont', $data2);
echo $client->__getLastResponse();
Result of php : looks like we got no xml document
or response
The requested URL was rejected. Please consult with your administrator."
But
As shown in the pictures the wdsl is working at he SoapUI but how to implement the options in the pure php or in the laravel framework. Thank you you for helping !!
SoapUI return response this xml:
xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">
Peak.Integration.ExternalInbound.Ekstre/ISOnlineEkstreServis/GetirDekontResponse
</a:Action>
</s:Header>
<s:Body>
<GetirDekontResponse xmlns="Peak.Integration.ExternalInbound.Ekstre">
<GetirDekontResult
xmlns:b="http://schemas.datacontract.org/2004/07/Peak.Integration.ExternalInbound.Ekstre.DataTransferObjects"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:IslemKodu>VBD0004</b:IslemKodu>
<b:IslemAciklamasi>Talimat için dekont bulunamadı.</b:IslemAciklamasi>
<b:DekontListesi xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</GetirDekontResult>
</GetirDekontResponse>
</s:Body>
</s:Envelope> ```
I found the solution :)
Quote from Alper Yaman, a member of Laravel Turkey group on Facebook.
To set WSA Addressing and add default wsa:To options on SoapClient connection in Laravel, you can follow these steps:
You can specify "soap_version" and "features" in the options array when creating the SoapClient object. Example:
$options = array(
'soap_version' => SOAP_1_2,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
);
$client = new SoapClient($wsdl, $options);
You can set WSA Addressing and add default wsa:To options by editing the headers of the request sent to the SoapClient object. Example:
$headers = array(
new SoapHeader("http://www.w3.org/2005/08/addressing", "Peak.Integration.ExternalInbound.Ekstre/ISOnlineEkstreServis/GetirDekont", $to),
new SoapHeader("http://www.w3.org/2005/08/addressing", "WEB SERVICE LINK ENDING WITH ?WSDL HERE", $action)
);
$client->__setSoapHeaders($headers);
Note: The $to and $action variables are required values for WSA Addressing.
After doing these operations, try to connect to the web service with the SoapClient object.
If you still get the error, please contact the server's administrator to ensure that the URL is not rejected.

Constructing and sending a Soap XML Request in PHP

I would like to use the ELOIS web service
Webservice interface:
To request pricing (see XML request):
For authentication:
The broker reference
The broker code
The broker password encrypted
The product code to which you wish Pricing
Action (new, update, quote, ...)
For pricing:
The information of the insured
The product-specific information
The reference quote if needed
Syntax Call :
To use the web service via SOAP, the parameters to use is :
Url: http://wsdev.elois.fr/Elois_Call.php
SOAPAction: getTarifs
example of an XML request
:
<auth>
<reference_courtier>ELOIS</reference_courtier>
<code_courtier>001234567</code_courtier>
<mot_de_passe_courtier>5d7a98bddsfg465qdfs0cb1ab4887eae8
</mot_de_passe_courtier>
<action>devispdf</action>
<code_produit>ACCEOPLUS</code_produit>
</auth>
<datas>
<reference_devis>123321</reference_devis>
<civilite1>Madame</civilite1>
<nom1>DUPONT</nom1>
<prenom1>Rosie</prenom1>
<date_naissance1>1970-02-01</date_naissance1>
<adresse1>25, rue Buffon</adresse1>
<code_postal1>75017</code_postal1>
<ville1>Paris</ville1>
<telephone1>06 06 06 06 06</telephone1>
<email1>mail#mail.fr</email1>
<perte_emploi1>non</perte_emploi1>
<dos_psy1>non</dos_psy1>
<chargement1>T30</chargement1>
<profession1>assureur</profession1>
<caution1>emprunteur</caution1>
<franchise1>90</franchise1>
<projet>travaux</projet>
<pret1Montant>100000</pret1Montant>
<pret1Quotite1>100</pret1Quotite1>
<pret1Garantie1>dcptia66</pret1Garantie1>
<pret1Duree>240</pret1Duree>
<pret1DiffAmor>0</pret1DiffAmor>
<pret1Taux>4</pret1Taux>
<pret1TypeTaux>fixe</pret1TypeTaux>
<date_effet>2014-09-25</date_effet>
<typePret1>Amort</typePret1>
</datas>
response returned by the web service
<DEVIS>
<IDENTIF>
<code_courtier>00123456</code_courtier>
<code_produit>ACCEOPLUS</code_produit>
<reference_devis>1234567</reference_devis>
</IDENTIF>
<ERROR>
</ERROR>
<TARIFS>
<pret1>
<montant>500000</montant>
<quotite>100</quotite>
<duree>160</duree>
<DCPTIA>4422.79</DCPTIA>
<ITTIPTIPP>3184.44</ITTIPTIPP>
<PE>0</PE>
<fraisAdhesion>176</fraisAdhesion>
<mensualite>47.5451875</mensualite>
<coutTotal>7607.23</coutTotal>
<tauxAnnuelMoyen>0.1141</tauxAnnuelMoyen>
</pret1>
<pret2>
<montant>120000</montant>
<quotite>100</quotite>
<duree>240</duree>
<DCPTIA>1920</DCPTIA>
<ITTIPTIPP>1280</ITTIPTIPP>
<PE>0</PE>
<fraisAdhesion>176</fraisAdhesion>
<mensualite>14.295833333333</mensualite>
<coutTotal>3431</coutTotal>
<tauxAnnuelMoyen>0.143</tauxAnnuelMoyen>
</pret2>
</TARIFS>
<PDF>
<libelle>DevisACCEOPLUS</libelle>
<url>http://www.elois.fr/modules/acceoplus/tmpdevis/WS145464549475.pdf
</url>
</PDF>
I would like to create a php script that sends a SOAP XML request to web service and receive the response
I tried this script :
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
$test = '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>
<auth>
<reference_courtier>ELOIS</reference_courtier>
<code_courtier>001234567</code_courtier>
...
<date_effet>2014-09-25</date_effet>
<typePret1>Amort</typePret1>
</datas>
</soap:Body>
</soap:Envelope>';
//Change this variables.
//$location_URL = 'http://write_your_location_url.asmx';
//$action_URL = 'http://write_your_action_to_perform_url.asmx&#8221';
$location_URL = 'http://wsdev.elois.fr/Elois_Call.php';
$action_URL = 'getTarifs';
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => '',
'trace' => 1,
));
try{
$order_return = $client->__doRequest($test,$location_URL,$action_URL,1);
//Get response from here
print_r($order_return);
}catch (SoapFault $exception){
var_dump(get_class($exception));
var_dump($exception);
}
?>
The web service returns me this error :
SOAP-ENV:ClientBad Request

EWS Push Subscription using PHP

Does anyone know how to respond to EWS (Exchange Web Services) Push Notifications using PHP.
I have initiated the EWS Push Subscription but cannot seem to send the correct SOAP response (in order to keep the subscription alive) when EWS sends my service a SOAP notification.
Taken from this page, I was under the impression that my SOAP response should be as follows:
<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<SubscriptionStatus>OK</SubscriptionStatus>
</SendNotificationResult>
</s:Body>
</s:Envelope>
However, EWS doesn't seem to be accepting my response as valid.
I have tried the following 2 code snippets with no luck:
Respond using a SOAP string with Content-Type header
header( 'Content-Type: text/xml; charset=utf-8' );
echo '<?xml version="1.0" encoding="utf-8"?>'.
'<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">'.
'<s:Body>'.
'<SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">'.
'<SubscriptionStatus>OK</SubscriptionStatus>'.
'</SendNotificationResult>'.
'</s:Body>'.
'</s:Envelope>';
OR Respond using a SOAP service
class ewsService {
public function SendNotification( $arg ) {
$result = new EWSType_SendNotificationResultType();
$result->SubscriptionStatus = 'OK';
return $result;
}
}
$server = new SoapServer( null, array(
'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
));
$server->setObject( new ewsService() );
$server->handle();
It might help to know that the classes I am using in my code come from the PHP-EWS library.
Any help would be greatly appreciated.
I also posted a more specific question here, but have had no responses so thought I would ask whether someone has actually gotten this working using any method.
It would seem that I was close but needed to include the NotificationService.wsdl when instantiating the SoapServer class. The WSDL then allows that SoapServer class to format the response accordingly.
$server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(
The WSDL was not included in the php-ews library download, however it is included with the Exchange Server installation. If like me you don't have access to the Exchange Server installation you can find the file here. I also had to add the following to the end of the WSDL because I was storing the WSDLs locally and not using autodiscovery:
<wsdl:service name="NotificationServices">
<wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
<soap:address location="" />
</wsdl:port>
</wsdl:service>
So the full working PHP code is as follows:
class ewsService {
public function SendNotification( $arg ) {
$result = new EWSType_SendNotificationResultType();
$result->SubscriptionStatus = 'OK';
//$result->SubscriptionStatus = 'Unsubscribe';
return $result;
}
}
$server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(
'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
));
$server->setObject( $service = new ewsService() );
$server->handle();
Which gives the following output:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Body>
<ns1:SendNotificationResult>
<ns1:SubscriptionStatus>OK</ns1:SubscriptionStatus>
</ns1:SendNotificationResult>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Hope that helps someone else because that took me a while to figure out!

Converting xml response to Array with php

Please i'm developping a php application, i want to know how to convert the xml reponse of a soap webservice into strings or array or json, i want to insert the values returned by the webservice into my database.
here is my xml respnse:
<env:Envelope xmlns:env="">
<env:Header/>
<env:Body>
<soap:getUserInfoResponse xmlns:soap="">
<getUserInfoResult>
<userInformation>
<detailuserInformationList>
<detailuserInformation>
<Name>Alex</Name>
<alias>Lex</alias>
<age>24</age>
<function>agent</function>
<birthdate>1</birthdate>
<birthmounth>02</birthmounth>
<birthyear>1990</birthyear>
<address>wall street</address>
<civility>mr</civility>
<gender>m</gender>
</detailuserInformation>
</detailuserInformationList>
<lastLogin>14:22</lastLogin>
<userId>A52241</userId>
<cnxTimes>125</cnxTimes>
</userInformation>
<requestTag/>
</getUserInfoResult>
</soap:getUserInfoResponse>
</env:Body>
</env:Envelope>
and here is my php code, calling the ws:
$client = new SoapClient('$url', array("trace" => 1, "exception" => 0));
$client->__setLocation('$url');
$response = $client->__soapCall("getUserInfo", array( parameters...);
print htmlspecialchars($client->__getLastResponse());
Try to use php SoapClient class
SoapClient class
If you generate WSDL use
NuSOAP
Firstly, check what do you have in $response in your code:
print htmlspecialchars($response);
Sceondly, this is proper way or working with SoapClient:
$client = new SoapClient($wsdl_url, array('trace' => 1, 'exception' => 0));
$response = $client->getUserInfo( /* parameters */ );
You'll get array in $response. You can laso view request and response XML with $client->__getLastRequest() and $client->__getLastResponse().

WSO2 WSF PHP SOAP XML request payload format

I have set-up wso2 PHP WS 2.1.0 framework on a centos server (PHP 5.2.10, apache/2.2.3) with the native PHP SOAP extension active. The sample WS clients work fine. The only difference in my WS installation to the default is that the wsf files are in the path structure /usr/lib64/php/modules/wsf_c/ instead of /var/lib/.
I am having trouble generating a complete SOAP request using the following client script -
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$reqPayloadString = <<<XML
<soap:Envelope xmlns:soap=”http://www.w3.org/2003/05/soap-envelope” xmlns:typ=”http://service.dataxmldistribution.argos.cls.fr/types”>
<soap:Header/>
<soap:Body>
<typ:xmlRequest>
<typ:username>user</typ:username>
<typ:password>password</typ:password>
<typ:platformId>'1,2,3,4,5'</typ:platformId>
<typ:nbDaysFromNow>10</typ:nbDaysFromNow>
</typ:xmlRequest>
</soap:Body>
</soap:Envelope>
XML;
$reqMessage = new WSMessage($reqPayloadString);
try {
$client = new WSClient(array(
"wsdl" => "http://ws-argos.cls.fr/argosDws/services/DixService?wsdl",
"to" => "http://ws-argos.cls.fr/argosDws/services/DixService",
"useSOAP" => 1.2,
"action"=>"getXml"
));
$resMessage = $client->request($reqPayloadString);
printf("Response = %s <br/>\n", htmlspecialchars($resMessage->str));
} catch (Exception $e) {
if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->code);
} else {
printf("Message = %s\n",$e->getMessage());
}
}
printf("<br/> Request = %s </br>",
htmlspecialchars($client->getLastRequest()));
printf("<br/> Response = %s </br>",
htmlspecialchars($client->getLastResponse()));
?>
The script returns the following -
Message = Invalid Input Message
Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body></soapenv:Body></soapenv:Envelope>
Response = <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="en">Fault occurred while processing.</soap:Text></soap:Reason></soap:Fault></soap:Body></soap:Envelope>
The client log shows one error - 'om_document.c(102) Unable to get root node'.
I assume that the fact that the xml request is missing from within the body element in the print-out from getLastRequest that I need to format the payload xml differently - possibly with namespaces?
I am unsure how this should look, so would be extremely gratefully of any advice, if this is the issue. I have tried this request with and without the 'wsdl' referenced in the WSClient array, and tried defining the payload as an array instead of an XML string (as you might with a native SOAP request).
Thank you, William

Categories