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
Related
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
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”';
$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
Hello i am very new to webservice, in php with below code i am trying to make soap request as shown in below XML, but it says Error
HTTP Error: Unsupported HTTP response status 405 Method Not Allowed (soapclient->response has contents of the response)
Questions:
How to pass headers?
How to pass FetchCalendarRequest with request like in XML?
I have used Nusoap here but if you have a SOAP PHP class solution it is also invited.
My code:
<?php
require_once('../lib/nusoap.php');
$client = new nusoap_client("http://webservices.test.com/ows/5.1/Availability.wsdl");
$err = $client->getError();
if ($err)
{
client_debug_error_message('Constructor error', $err, $client);
exit;
}
// Call the SOAP method
$result = $client->call(
'FetchCalendar',
array(
'StayDateRange' => array(
'StartDate' => '2013-10-01',
'EndDate' => '2013-10-10',
),
),
);
// Check for a fault
if ($client->fault)
{
debug_preformatted('Fault', $result);
}
else
{
// Check for errors
$err = $client->getError();
if ($err)
{
debug_preformatted('Error', $err);
}
else
{
debug_preformatted('Result', $result);
}
}
// Display the request and response
client_debug_dump($client);
XML :
<?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>
<OGHeader transactionID="005435" timeStamp="2008-12-09T13:26:56.4056250-05:00" xmlns="http://webservices.test.com/og/4.3/Core/">
<Origin entityID="OWS" systemType="WEB" />
<Destination entityID="WEST" systemType="ORS" />
</OGHeader>
</soap:Header>
<soap:Body>
<FetchCalendarRequest xmlns:a="http://webservices.test.com/og/4.3/Availability/" xmlns:hc="http://webservices.test.com/og/4.3/HotelCommon/" xmlns="http://webservices.test.com/ows/5.1/Availability.wsdl">
<HotelReference chainCode="AXA" hotelCode="AXAMUM" />
<StayDateRange>
<hc:StartDate>2013-10-01</hc:StartDate>
<hc:EndDate>2013-10-10</hc:EndDate>
</StayDateRange>
<GuestCount>
<hc:GuestCount ageQualifyingCode="ADULT" count="1" />
<hc:GuestCount ageQualifyingCode="CHILD" count="0" />
</GuestCount>
</FetchCalendarRequest>
</soap:Body>
</soap:Envelope>
Post Url :http://000.000.000.00:8080/ows_ws_51/Availability.asmx
Soap Action : http://webservices.test.com/ows/5.1/Availability.wsdl#FetchCalendar
Edit: Working Solution 16 Sep 2013
This solution is with Soap PHP Class only I want it to work with Nusoap bow.
<?php
$wsdl = "http://###.###.###.##:8080/ows_ws_51/Availability.asmx?wsdl";
$client = new SoapClient($wsdl, array( 'soap_version' => SOAP_1_1,'trace' => true,));
//=========== Header Setting ============
$ns = 'http://webservices.micros.com/og/4.3/Availability/'; //Namespace of the WS.//Body of the Soap Header.
$strHeaderComponent_Session = <<<XML
<OGHeader transactionID="005435" timeStamp="2008-12-09T13:26:56.4056250-05:00" xmlns="http://webservices.micros.com/og/4.3/Core/">
<Origin entityID="OWS" systemType="WEB" />
<Destination entityID="WEST" systemType="ORS" />
</OGHeader>
XML;
$objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
$objHeader_Session_Outside = new SoapHeader($ns , 'SessionHeader', $objVar_Session_Inside);
// More than one header can be provided in this array.
$client->__setSoapHeaders(array($objHeader_Session_Outside));
//============== Request ================
$xml = <<<XML
<FetchCalendarRequest xmlns:a="http://webservices.micros.com/og/4.3/Availability/" xmlns:hc="http://webservices.micros.com/og/4.3/HotelCommon/" xmlns="http://webservices.micros.com/ows/5.1/Availability.wsdl">
<HotelReference chainCode="AXA" hotelCode="{$DdlHotels}" />
<StayDateRange>
<hc:StartDate>{$Arrive}</hc:StartDate>
<hc:EndDate>{$Depart}</hc:EndDate>
</StayDateRange>
<GuestCount>
<hc:GuestCount ageQualifyingCode="ADULT" count="1" />
<hc:GuestCount ageQualifyingCode="CHILD" count="0" />
</GuestCount>
</FetchCalendarRequest>
XML;
$args = array(new SoapVar($xml, XSD_ANYXML));
try
{
$response = $client->__soapCall( 'FetchCalendar', $args );
}
catch (SoapFault $e)
{
echo "Error: {$e}"; exit;
}
You can use PHP's built in SOAP library to create a SOAP client and call a method from the WSDL, try something like this:
$client = new SoapClient($wsdl, array( 'soap_version' => SOAP_1_1,
'trace' => true,
));
try {
$params = array(
//Your parameters here
);
$res = $client->__soapCall( 'SoapMethod', $params );
return $res;
} catch (SoapFault $e) {
echo "Error: {$e}";
}
//for debugging what the outgoing xml looks like
$client->__getLastRequest();
The WSDL should help structure the xml for your params. If you cannot get that to work the way you want you could try passing the xml yourself using SoapVar() and setting the encode to XSD_ANYXML.
If you also need to add additional header information take a look at this example from the PHP docs.
$params = array(//your params as specified by documentation);
$result = $client->call(array("Availability"=>$params));
Might I suggest trying to learn SOAP with a different example web service. The wsdl document published for this service appears to be incomplete, as they have entered the incorrect SOAP address for the Availability service. With an incorrect or incomplete WSDL document, the SOAP library you are using will not be able to form a valid SOAP request and send it to the correct endpoint.
<wsdl:service name="AvailabilityService">
<wsdl:port name="AvailabilityPort" binding="tns:AvailabilityBinding">
<soap:address location="http://tempuri.org"/>
</wsdl:port>
</wsdl:service>
As you can see, the AvailabilityService endpoint is described as http://tempuri.org, which is explained as a default test namespace here.
In your original post, you have the 'POST URL' described as http://000.000.000.00:8080/ows_ws_51/Availability.asmx. How is anyone supposed to try the example, if you list the 'POST URL' an as obviously invalid URL.
You have also listed the WSDL document as http://webservices.test.com/ows/5.1/Availability.wsdl, which is also an invalid URL.
Here is a PHP example, accessing a valid WSDL document, using PHP's built-in SOAP library, which can be enabled by enabling the php_soap.dll extension in your php.ini file.
<?php
$wsdl = "http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl";
$client = new SoapClient($wsdl, array(
"trace" => 1,
"exceptions" => 0));
$parameters = array("request" => "IBM");
$value = $client->GetStockQuote($parameters);
$json = json_encode($value);
echo $json;
Note: The following is more of a comment than an answer. I leave it here for further reference as it would not fit into a comment box and it references existing Q&A possible worth for future visitors
You ask two questions regarding Nusoap here:
How to pass headers?
How to pass FetchCalendarRequest with request like in XML?
The first one How to pass headers? has been outlined already in this Q&A:
NuSoap PHP webservice with soap headers
As you have not written specifically in your question what of this (and possible other of the) existing Q&A didn't work for you, this might not suit your needs but you need to give detailed feedback first I'd say.
The second question How to pass FetchCalendarRequest with request like in XML? you probably mean how to call a SOAP action or method ("Request") that has been named in a WSDL. This has already been covered as well for Nusoap on the Stackoverflow website:
Nusoap use existing WSDL how to?
As you have not written specifically in your question what of this (and possible other of the) existing Q&A didn't work for you, this might not suit your needs but you need to give detailed feedback first I'd say to turn this into a concrete programming question.
BTW Stackoverflow works best by asking one question at a time.
I am newbie to services, i am currently calling .net WCF service in PHP using SoapClient object. Code is as follows:
$arr2=array('paymentVendorCode'=>"test1",'transactionNumber'=>123456789,'dataSource'=>'Ghana_QA','customerNumber'=>45678912,'amount'=>10,'invoicePeriod'=>1,'currency'=>'GHC','paymentDescription'=>'CashPayment','methodofPayment'=>'CASH','productCollection'=>'PRCC4');
$certFile = "certs/Entrust.pem";
$options = array('soap_version' => SOAP_1_1 , 'local_cert' => $certFile , 'exceptions' => true ,'trace' => true ,'wdsl_local_copy' => true ,'ssl' => array('verify_peer' => false) ,'https' => array('curl_verify_ssl_peer' => false, 'curl_verify_ssl_host' => false)
);
try
{
echo "SOAP Client Object Made <br />";
//To Make soap client using WSDL files offline
$client = new SoapClient("RTPP_Web_Service_WSDL_20130306/multichoice.paymentservice.wsdl",$options);
}
catch(SoapFault $E)
{
echo "Error:--> ".$E->faultstring;
}
print_r($client->__getFunctions());
try
{
echo $pmt_customer=$client->__call("SubmitPayment", $arr2)."<br /><br />";
}
catch(SoapFault $fault)
{
echo "came here in catch";
trigger_error("SOAP Fault:(faultcode: {$fault->faultcode}\n"."faultstring: {$fault->faultstring})", E_USER_ERROR);
}
I have go through all WSDL files i am using and got all elements, messages, operations, parameters etc. In one of the WSDL file soap address is as follows:
<soap:address location="https://wispqa.multichoice.co.za/PaymentServicePerimeter/Intermediate.svc" />
which is actual address of service being called, normally services are called with ?WSDL at the end of url but even after adding this at the end of above url the service page appearance remains same.
One thing in service documentation is written as "The service currently does not make use of message contracts."
I am sending request to service calling one of its methods from the list that i got by calling "$client->__getFunction()". But instead of response it is giving fatal error that can be seen from the screenshot at http://i.stack.imgur.com/GvS3d.png.
I have been working on it for a almost a week but got stuck here. Please if anybody can get me out of here. Thanks in advance.
I got my answer, What i was missing is soap action for the method to be called. I have given soap action by visiting WSDL files thoroughly and found soap action for method i was calling as:
$submitpayment_action = "http://MultiChoice.PaymentService/ServiceContracts/PaymentServiceContract/SubmitPayment";
Also i have changed format of my request by using xml format whose excerpt is as follows(i have got this xml format by using SOAPUI tool):
$submitpay = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:mes=\"http://MultiChoice.PaymentService/MessageContracts\"
xmlns:ser=\"http://MultiChoice.PaymentService/ServiceContracts\"
xmlns:dat=\"http://MultiChoice.PaymentService/DataContracts\"
xmlns:mcom=\"http://mcomp.scontracts\" xmlns:mcom1=\"http://mcomp.dcontracts\">
<soapenv:Header/>
<soapenv:Body>
<mes:SubmitPaymentRequest>
<ser:PaymentRequest>
<dat:paymentVendorCode>".$vendorcode."</dat:paymentVendorCode> .......
and finally using this "__doRequest" SOAP method to call service method as:
$response = $client->__doRequest($submitpay,$location,$submitpayment_action,SOAP_1_1,$one_way = 0);
print_r($response);
This show me the desired response. Now one can extract required information from the response using "simplexml_load_string($response);" , "registerXPathNamespace()" and "xpath('//string');" methods.
I'm trying to communicate with the eWay server and had everything working until we ended up needing to switch to a different API. The problem is that SoapClient is creating a different namespace for the header (that includes the authentication) then from the body, which, obviously, doesn't get me any results. Instead, I get eWay's servers saying it must have the authentication information.
Here's my code:
$client = new SoapClient($url.'?WSDL', array('trace'=>TRUE));
// Set our SOAP Headers for authentication
$header_body = array(
'eWAYCustomerID' => $gateway['customer_id'],
'Username' => $gateway['username'],
'Password' => $gateway['password']
);
$header_var = new SoapVar($header_body, SOAP_ENC_OBJECT);
$header = new SOAPHeader('http://www.eway.com.au/gateway/managedpayment', 'eWAYHeader', $header_body);
//$client->__setSoapHeaders($header);
try {
$response = $client->__soapCall($action, $xml, null, $header);
} catch (SoapFault $e)
{
echo 'SOAP Fault: '. $e->getMessage()."<br>\n";
}
As you can see, I've tried it with and without using a SoapVar for the header, all with no luck.
Here's the XML request that is being created:
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.eway.com.au/gateway/managedpayment" xmlns:ns2="http://www.eway.com.au/gateway/managedpayment">
<soap-env:header>
<ns2:ewayheader>
<ewaycustomerid>87654321</ewaycustomerid>
<username>test#eway.com.au</username>
<password>test123</password>
</ns2:ewayheader>
</soap-env:header>
<soap-env:body>
<ns1:createcustomer>...</ns1:createcustomer>
This may be an obvious question, but did you try specifying the typename and type namespace in the SoapVar() call?