I have to call a SOAP with this structure (obtained with SOAPUI):
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:v3='http://v3.ws.server.ldap.ws.xxx/'
xmlns:cod='http://server/Usr/codeUsr'>
<soapenv:Header/>
<soapenv:Body>
<v3:getUsr>
<cod:codeUsr>P012997</cod:codeUsr>
</v3:getUsr>
</soapenv:Body>
</soapenv:Envelope>
The client is:
$client = new SoapClient("http://xxx.xxx.xxx.xxx:8080/ws-ldap3/wServiceV3?wsdl");
So far, I tried:
echo "a(TT).<br/>";var_dump($client->getUsr('P012997'));
echo "b(TT).<br/>";var_dump($client->getUsr(array('cod' => 'P012997')));
echo "c(TT).<br/>";var_dump($client->getUsr(array('codeUsr' => 'P012997')));
echo "d(TT).<br/>";var_dump ($client->__soapCall('getUsr', array('parameters' => array('cod' => 'P012997'))));
echo "e(TT).<br/>";var_dump ($client->__soapCall('getUsr', array('parameters' => array('codeUsr' => 'P012997'))));
echo "f(TT).<br/>";var_dump ($client->__soapCall('getUsr', array('cod' => 'P012997')));
echo "g(TT).<br/>";var_dump ($client->__soapCall('getUsr', array('codeUsr' => 'P012997')));
without success. How can I pass the parameter codeUsr?
TIA,
I finally solved the problem (not the case) using CURL. I send the XML exactly as needed.
$xml="<same as before>";
$sDo = curl_init();
curl_setopt($sDo, CURLOPT_URL, "http://xxx.xxx.xxx.xxx:8080/ws-ldap3/wServiceV3?wsdl");
curl_setopt($sDo, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($sDo, CURLOPT_TIMEOUT, 10);
curl_setopt($sDo, CURLOPT_RETURNTRANSFER, true);
curl_setopt($sDo, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($sDo, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($sDo, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($sDo, CURLOPT_POST, true );
curl_setopt($sDo, CURLOPT_POSTFIELDS, $xml);
curl_setopt($sDo, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8", "Content-Length: " . strlen($xml)));
$result = curl_exec($sDo);
Post it in case somebody else have a bottleneck and can't spend days to figure how to make it work.
Related
I have been trying, for days, to send a simple XML request to an API. Even with the help of the tech support, absolutely nothing works. I still get an error telling me that my XML isn't well-formed or is invalid.
Here is my cURL request:
$data = array_merge([
'ssl_transaction_type' => "$transactionType",
'ssl_merchant_id' => $this->merchant_id,
'ssl_user_id' => $this->user_id,
'ssl_pin' => $this->pin
], $data);
$xml = new \SimpleXMLElement('<txn/>');
$data = array_flip($data);
array_walk_recursive($data, array ($xml, 'addChild'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getXMLUrl());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/x-www-form-urlencoded'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("xmldata=" . explode(PHP_EOL, $xml->asXML())[1])));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
Why do I explode the XML? It's because I need to only get the part with the root, not the version, etc. according to the tech support.
I followed this: XML request is not well-formed or request is incomplete but it still doesn't work.
I've never had the opportunity to submit to a WSDL SOAP web service and am running into some issues. Im using PHP cURL to submit the form to a known back end fist, then secondly to the WSDL SOAP service. The first part is working fine, so I will skip over that. I have spent the better part of 3 days trying different solutions I've found on the web, and my own after reading SOAP documentation, with no luck.
Here is what I'm using to submit to the WSDL
<?php
//first cURL POST HERE - works fine
//second cURL POST BELOW
$FName = $_POST['FirstName'];
$Lname = $_POST['LastName'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone1'];
$soapURL = "https://something.com/IBWeb/IBDemoManager/IBDemoManager.asmx?wsdl";
$soapUser = "USR";
$soapPassword = "PWD";
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$xml_post_string = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.htdocs.openecry">
<soapenv:Header/>
<soapenv:Body>
<web:demosetup soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<AccessCode xsi:type="xsd:string">G0!=#%fut40</AccessCode>
<NewUserCategoryName xsi:type="xsd:string">OFLDemo</NewUserCategoryName>
<TemplateUserName xsi:type="xsd:string">OFLUser</TemplateUserName>
<CusType xsi:type="xsd:string">Indirect</CusType>
<WLabelID xsi:type="xsd:string">276</WLabelID>
<SCodeID xsi:type="xsd:string"></SCodeID>
<SoftID xsi:type="xsd:string">1</SoftID>
<FName xsi:type="xsd:string">'.$FName.'</FName>
<LName xsi:type="xsd:string">'.$LName.'</LName>
<Email xsi:type="xsd:string">'.$Email.'</Email>
<Phone xsi:type="xsd:string">'.$Phone.'</Phone>
<Address xsi:type="xsd:string"></Address>
<City xsi:type="xsd:string"></City>
<Zip xsi:type="xsd:string"></Zip>
<State xsi:type="xsd:string"></State>
<Country xsi:type="xsd:string"></Country>
<CountryName xsi:type="xsd:string"></CountryName>
<AssetTypes xsi:type="xsd:string">Futures</AssetTypes>
<How xsi:type="xsd:string">OFL webservice</How>
<MoreEmail xsi:type="xsd:string"></MoreEmail>
<RemoteAddr xsi:type="xsd:string">'.$hostname.'</RemoteAddr>
<CampaignID xsi:type="xsd:string"></CampaignID>
</web:demosetup>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
//IS SOAPAction the same as the endpoint "$soapURL"?//
"SOAPAction: https://something.com/IBWeb/IBDemoManager/IBDemoManager.asmx?wsdl",
"Content-length: ".strlen($xml_post_string),
);
$url2 = $soapURL;
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url2 );
curl_setopt($soap_do, CURLOPT_HEADER, false);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
$result = curl_exec($soap_do);
echo '<pre>';
print_r($result);
curl_close($soap_do);
//print 'Operation completed without any errors';
}
Here are just some comments:
Try to disable the SSL check (just for testing):
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0);
You should call curl_close($ch2); as last. Example:
$output2 = curl_exec($ch2);
if(curl_errno($ch2))
echo curl_error($ch2);
} else {
echo $output2;
}
curl_close($ch2); // <--- close here
You could also try the Zend SOAP library.
If you don't like CURL try Guzzle to make an HTTP request.
I have not worked with SOAP API before.
I want to execute a SOAP API with XML data request.
I have tried but did not get success.
https://www.getpayments.com/docs/#processrealtimetokenpayment
This is the payment gateway URL which I have want to call.
I have used below code :
$xml = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:px="https://px.ezidebit.com.au/">
<soapenv:Header />
<soapenv:Body>
<px:ProcessRealtimeTokenPayment>
<px:digitalKey>715C0799-307B-4BF4-7B1D-4153201FC0A1</px:digitalKey>
<px:token>3723758</px:token>
<px:paymentAmountInCents>1600</px:paymentAmountInCents>
<px:customerName>Hiren Patel</px:customerName>
<px:paymentReference>123456789</px:paymentReference>
</px:ProcessRealtimeTokenPayment>
</soapenv:Body>
</soapenv:Envelope>';
$soapUrl = "https://api.demo.ezidebit.com.au/v3-5/pci?singleWsdl";
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $soapUrl );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($xml) ));
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
curl_close($soap_do);
echo "<pre>";print_r($result);
die;
It throws below error :
a:ActionNotSupportedThe message with Action
'ProcessRealtimeTokenPayment' cannot be processed at the receiver, due
to a ContractFilter mismatch at the EndpointDispatcher. This may be
because of either a contract mismatch (mismatched Actions between
sender and receiver) or a binding/security mismatch between the sender
and the receiver. Check that sender and receiver have the same
contract and the same binding (including security requirements, e.g.
Message, Transport, None).Curl call success.
Please anyone can guide me in this?
Thank you in advance.
Here is an example with SoapClient:
<?php
$soap = new SoapClient(
'https://api.demo.ezidebit.com.au/v3-5/pci?singleWsdl',
array(
'trace' => 1,
'exceptions' => 1
)
);
$soap->ProcessRealtimeCreditCardPayment(
array(
'DigitalKey' => '715C0799-307B-4BF4-7B1D-4153201FC0A1',
'Token' => '3723758',
'PaymentAmountInCents' => '1600',
'CustomerName' => 'Hiren Patel',
'PaymentReference' => '123456789'
)
);
echo $soap->__getLastRequest() . "\n";
echo $soap->__getLastResponse() . "\n";
You can save it into the file and run with:
php file.php
Hi Can anyone explain me in implementing below SOAP XML in PHP, I saw some questions they were handled using CURL but I want to use SoapClient library in PHP Can anyone help me.
I saw some people used below code in PHP get the simple SOAP , How can I implement the same way in my code
<?php
//Create the client object
$soapclient = new SoapClient('http://www.example.com:8080/test/services/test?wsdl');
//Use the functions of the client, the params of the function are in
//the associative array
$params = array(
'locationID' => '19087525238255',
'custFirstName' => 'Seure',
'custLastName' => 'Install',
'customerType' => 'RESI'
);
$response = $soapclient->octService($params);
var_dump($response);
?>
SOAP XML
<soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:com = "http://test.com/">
<soapenv:Header/>
<soapenv:Body>
<com:OCTService>
<locationID>19087525238255</locationID>
<customer>
<custFirstName>JOHN</custFirstName>
<custLastName>ADAM</custLastName>
<customerType>RESI</customerType>
</customer>
<order>
<orderScheduleType>NoSchedule</orderScheduleType>
<orderScheduledate/>
<reasonCode>NT</reasonCode>
<salesRep>0001</salesRep>
</order>
<Equipments>
<equipment>
<serialNumber>*</serialNumber>
<type>N</type>
</equipment>
<equipment>
<serialNumber>*</serialNumber>
<type>NH</type>
</equipment>
<equipment>
<serialNumber>*</serialNumber>
<type>NH</type>
</equipment>
</Equipments>
<csgServiceCodes>
<CSGServiceCode>
<rateCode>SR002</rateCode>
<packageCode/>
</CSGServiceCode>
<CSGServiceCode>
<rateCode>BA</rateCode>
<packageCode/>
</CSGServiceCode>
</csgServiceCodes>
<voiceFeatures>
<nativeNumbersCount>0</nativeNumbersCount>
<portedNmbers>?</portedNmbers>
</voiceFeatures>
<HuntGroup>
<huntGroupType>?</huntGroupType>
</HuntGroup>
</com:OCTService>
</soapenv:Body>
</soapenv:Envelope>
I not able to achieve using CURL POST.
Here important thing is SOAPAction which you can use in the WSDL document
$headers = array(
"Accept-Encoding: gzip,deflate",
"Content-Type: text",
"Cache-Control: no-cache",
"Username: yourusername",
"Password: password",
"SOAPAction: urn:OCTService",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
echo $response;
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
I use cURL but untill now I used it for requesting data from servers. But now I want ot write API and data will be requested with cURL. But I don't know how Server reads data from cURL request.
This is my "client server" side request:
function sendRequest($site_name,$send_xml,$header_type=array('Content-Type: text/xml'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site_name);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$send_xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header_type);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec($ch);
return $result;
}
$xml = "<request>
<session>
<user>exampleuser</user>
<pass>examplepass</pass>
</session>
</request>";
$sendreq = sendRequest("http://sitename.com/example.php",$xml);
echo $sendreq;
How do I need to write "main server" side script so I can read what user and pass from request are???
Thank you a lot.
To just be able to read it try this
curl_setopt($ch, CURLOPT_POSTFIELDS,array('data'=>$send_xml));
Then
print_r($_POST['data'])
Alternatively skip the XML and try something like this:
$data = array(
'request' => array(
'session' => array(
'user'=>'exampleuser',
'pass'=>'examplepass')
)
);
$sendreq = sendRequest("http://sitename.com/example.php",$data);
In example.php
print_r($_POST)