How to make a SOAP call in PHP? - php

I have to make a SOAP Call on a Axis2 Server with parameters, but I have a lot of problems, I done this on SOAPUI and works fine.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<Seguridad>
<usuario>0000000000</usuario>
<password>9FDB5D2R4J62755C7DA205S52D8G4H36D4CRCB94978BC40DDD2D4220CB63FE7E</password>
<fechaSistema>02/01/2015</fechaSistema>
</Seguridad>
</soapenv:Header>
<soapenv:Body>
<ws:enviaCONVOL xmlns:ws="http://ws.convol/">
<!--Optional:-->
<arg0>2014-12-31</arg0>
<!--Optional:-->
<arg1>11:48:46</arg1>
<!--Optional:-->
<arg2>ZmUxMzc3ZDmyYTc3YTAyZjM2YT8lZDc4MzgwOTZhY2Y0YTM1MDg3Wg==</arg2>
<!--Optional:-->
<arg3>ZmUxMzc3ZDmyYTc3YTAyZjM2YT8lZDc4MzgwOTZhY2Y0YTM1MDg3Wg==</arg3>
</ws:enviaCONVOL>
</soapenv:Body>
</soapenv:Envelope>
I need do this with soap in PHP and MTOM, and the arg2 is a CID from a zip file.
When I tried to implement the header and send the SOAP call to the server always receive "Internal Error " or "Unknown Content-Encoding". I am having some problems with the headers and the correct implementation of the call, I need to send like the code.
what i get with PHP:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.convol/"><SOAP-ENV:Body><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<Seguridad>
<usuario>0000105847</usuario>
<password>9FDBDE265822755C7DA2058053B61580736ECB94978BC40DDD2D4220CB63FE7E</password>
<fechaSistema>02/01/2015</fechaSistema>
</Seguridad>
</soapenv:Header>
<soapenv:Body>
<ws:enviaCONVOL xmlns:ws="http://ws.convol/">
<!--Optional:-->
<arg0>2014-12-31</arg0>
<!--Optional:-->
<arg1>11:48:46</arg1>
<!--Optional:-->
<arg2>ZmUxMzc3ZDQyYTc3YTAyZjM2YThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg2>
<!--Optional:-->
<arg3>ZmUxMzc3ZDQyYTc3YTAyZjM2YThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg3>
</ws:enviaCONVOL>
</soapenv:Body>
</soapenv:Envelope></SOAP-ENV:Body></SOAP-ENV:Envelope>
I had this on PHP
try{
$client=new SoapClient('https://www.convolmiscelaneapruebas.pemex.com/ServiciosCVWEB/ServicioEnviaCONVOLService/ServicioEnviaCONVOLService.wsdl',array( 'trace' => 1, 'exceptions' => 0 ));
$header = '<SOAP-ENV:Header>
<Seguridad>
<usuario>0000000000</usuario>
<password>9FDBDE265822755C50dHD5D33B61580736ECB94978BC40DDD2D4220CB63FE7E</password>
<fechaSistema>02/01/2015</fechaSistema>
</Seguridad>
</SOAP-ENV:Header>';
$xml = '<ns1:enviaCONVOL>
<!--Optional:-->
<arg0>2014-12-31</arg0>
<!--Optional:-->
<arg1>11:48:46</arg1>
<!--Optional:-->
<arg2>ZmUxMzc3ZDQyYTc3YTAyZddd5IMKYThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg2>
<!--Optional:-->
<arg3>ZmUxMzc3ZDQyYTdnHD90D3185D4MzgwOTZhY2Y0YTM1MDg3Ng==</arg3>
</ns1:enviaCONVOL>
';
$args = array(new SoapVar($xml, XSD_ANYXML));
$res = $client->__soapCall('enviaCONVOL', $args);
echo "<hr>Last Request<br>";
echo "<pre>", htmlspecialchars($client->__getLastRequest()), "</pre>";
print_r($res);
}catch (SoapFault $fault){
echo "SOAPFault: ".$fault->faultcode." - ".$fault->faultstring.' - '.$fault->getMessage();
}
I canĀ“t put the Header in the right place...

I used NuSoap
$wsdl = "https://www.convolmiscelaneapruebas.pemex.com/ServiciosCVWEB/ServicioEnviaCONVOLService/ServicioEnviaCONVOLService.wsdl";
$client = new nusoap_client($wsdl,TRUE);
$header =
"<Seguridad>
<usuario>0000000000</usuario>
<password>4e671bf08913d677c56359262117c8e67a5507b165f727288a487040bf2a1780</password>
<fechaSistema>02/01/2015</fechaSistema>
</Seguridad>";
$operation = array('arg0' => '2014-12-31',
'arg1' => '11:48:46',
'arg2'=>'12095866ae89b7dbcd44640189c57e185918192739040eb52ba5b==',
'arg3'=>'ZmU5866axMzc3ZDQyJmdAyZjM2YThlZDb7dbcd446401YTM1Mg3Ng=='
);
$client->setHeaders($header);
$res = $client->call('enviaCONVOL',$operation);

Related

SOAP envelope with header authentication call php

I have to consume a webservice, but can't find a proper way to create the call.
This is the xml the company provide as example
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Qpay.POS.Gateway.ServiceContracts" xmlns:urn1="urn:Qpay.POS.Gateway.DataContracts">
<soapenv:Header/>
<soapenv:Body>
<urn:GetProvidersRequest>
<!--Optional:-->
<urn:Header>
<urn1:CertPublicKey>XX-XX-XX-XX-XX</urn1:CertPublicKey>
<!--Optional:-->
<urn1:UIID>XX</urn1:UIID>
<urn1:User>XXXX</urn1:User>
</urn:Header>
</urn:GetProvidersRequest>
</soapenv:Body>
</soapenv:Envelope>
Tried using this:
$soapURL = "https://pos.qpay123.biz/dBar/Gateway.svc?" ;
$soapParameters = Array('UIID' => "63", 'User' => "System") ;
$soapFunction = "GetProvidersRequest" ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction) ;
var_dump($soapResult);
But i get a false as var dump, can you point me on the right direction to solve it?
Thanks

How can I create PHP SOAP request to call web service implemented in ColdFusion

I have implemented web service in ColdFusion. I am trying to call that webservice using php. But getting errors.
Can someone help me to prepare SAOP request in php? xml request is below in SOAP UI.
<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://localhost:8501/webservice">
<soapenv:Header/>
<soapenv:Body>
<web:ASK soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<AgentID> 1 </AgentID>
<Passwd> 12345 </Passwd>
<TransactionNumber >XXX </TransactionNumber >
<Sign >XXX </Sign >
</soapenv:Body>
</soapenv:Envelope>
I have used below code in php
$soapUrl = "http://domain.com/webservice/transaction.cfc?WSDL"; // asmx URL of WSDL
$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://localhost:8501/webservice">
<soapenv:Header/>
<soapenv:Body>
<web:ASK soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<AgentID> 1 </AgentID>
<Passwd> 12345 </Passwd>
<TransactionNumber >XXX </TransactionNumber >
<Sign >XXX </Sign >
</soapenv:Body>
</soapenv:Envelope>';
$xml_array['AgentID'] = '1';
$xml_array['Passwd'] = "12345";
$xml_array['TransactionNumber'] = "XXX";
$client = new SoapClient($soapUrl, array( 'soap_version'=>SOAP_1_1, 'trace'=>1));
$xml= $client-> ASK($xml_array,$soapUrl,"POST",0);
(OR)
$xml= $client-> ASK($xml_post_string ,$soapUrl,"POST",0);
print "<pre>";
print_r($xml);
print "</pre>";
?>
Returns below error in both case
Fatal error: Uncaught SoapFault exception: [Server.userException] No such operation 'ASK' in C:\xampp\htdocs\webservice\

PHP SOAP Request not working

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)
Q.
1)how to pass headers
2)how to pass FetchCalendarRequest
i have used nusoap here but if u have soap php class solution is also invited.
<?php
error_reporting(E_ALL);
require("../lib/nusoap.php");
error_reporting(E_ALL ^ E_NOTICE);
$ERROR_MSG = '';
$s_WSPROTOCOL = 'http';
$s_WSHOSTNAME = '###.###.###.##';
$s_WSPORT = ':8080';
$s_WSPATHNAME = 'ows_ws_51/Availability.asmx?WSDL';
$s_WSTIPOOP = 'FetchCalendar';
$parameters['StayDateRange'] = array('StartDate' => '2013-10-01','EndDate' => '2013-10-10');
echo $s_WSTIPOOP."<br />";
echo $s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME."<br /><br /><br />";
$client = new nusoap_client($s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME, true);
$result = $client->call($s_WSTIPOOP, $parameters);
if ($client->fault) {
echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>';
print_r($result); echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
?>
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
It seems you don't have to send credentials, this returns a answere:
<?php
$soap = new SoapClient('http://webservices.micros.com/ows/5.1/Availability.wsdl', array("trace" => 1, "exception" => 0));
var_dump($soap->FetchCalendar(array(
'StayDateRange' => array(
'StartDate' => '2013-10-01',
'EndDate' => '2013-10-10'
)
)));
It still needs a HotelReference tough.
===
Here is how to set SoapHeaders:
<?php
$headerbody = array('Origin' => 'foo',
'Destination' => 'bar');
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);
$soap->__setSoapHeaders($header);
More on the subject can be found: http://php.net/manual/en/soapclient.setsoapheaders.php
===
Here is the soapui response when you want to perform that method
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:core="http://webservices.micros.com/og/4.3/Core/" xmlns:ava="http://webservices.micros.com/ows/5.1/Availability.wsdl" xmlns:hot="http://webservices.micros.com/og/4.3/HotelCommon/">
<soapenv:Header>
<core:OGHeader transactionID="?" authToken="?" timeStamp="?" primaryLangID="E" channelValidation="true" terminalID="?">
<core:Origin entityID="?" organizationID="?" systemType="?"/>
<core:Destination entityID="?" organizationID="?" systemType="?"/>
<!--Optional:-->
<core:Intermediaries>
<!--1 or more repetitions:-->
<core:EndPoint entityID="?" organizationID="?" systemType="?"/>
</core:Intermediaries>
<!--Optional:-->
<core:Authentication>
<core:UserCredentials>
<core:UserName>?</core:UserName>
<core:UserPassword>?</core:UserPassword>
<core:Domain>?</core:Domain>
<!--Optional:-->
<core:SecurityId>?</core:SecurityId>
</core:UserCredentials>
<!--Optional:-->
<core:Licence>
<!--Optional:-->
<core:Key>?</core:Key>
</core:Licence>
</core:Authentication>
</core:OGHeader>
</soapenv:Header>
<soapenv:Body>
<ava:FetchCalendarRequest>
<ava:HotelReference chainCode="?" hotelCode="?">?</ava:HotelReference>
<ava:StayDateRange>
<hot:StartDate>?</hot:StartDate>
<!--You have a CHOICE of the next 2 items at this level-->
<hot:EndDate>?</hot:EndDate>
<hot:Duration>?</hot:Duration>
</ava:StayDateRange>
<!--Optional:-->
<ava:GuestCount isPerRoom="?">
<!--1 or more repetitions:-->
<hot:GuestCount ageQualifyingCode="?" otherAgeQualifyingCode="?" age="?" count="?"/>
</ava:GuestCount>
<!--Optional:-->
<ava:RatePlanCode>?</ava:RatePlanCode>
<!--Optional:-->
<ava:RoomTypeCode>?</ava:RoomTypeCode>
<!--Optional:-->
<ava:BlockCode>?</ava:BlockCode>
<!--Optional:-->
<ava:CorporateCode>?</ava:CorporateCode>
<!--Optional:-->
<ava:PromotionCode>?</ava:PromotionCode>
<!--Optional:-->
<ava:NumberOfNights>?</ava:NumberOfNights>
<!--Optional:-->
<ava:RestrictedMode>?</ava:RestrictedMode>
<!--Optional:-->
<ava:InventoryMode>?</ava:InventoryMode>
</ava:FetchCalendarRequest>
</soapenv:Body>
</soapenv:Envelope>
If i compare it to your settings, the options you send with the response you do not provide the UserCredentials. And that gives me the feeling you get the error that you are not allowed to use that method. Start with providing your credentials.

WSDL Client Problem With PHP

I would like to send the following XML request to a WSDL web service :
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>
How can I do this? I tried PHP soap extension and also NuSOAP with no success :(
Thanks for your help.
Have you tried HttpRequest::send ? E.g. see the example at http://www.php.net/manual/en/function.httprequest-send.php#95734 and fill in your own data:
<?php
//set up variables
$theData = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>';
$url = 'http://www.example.com';
$options = array();
//create the httprequest object
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options);
//add the content type
$httpRequest_OBJ->setContentType = 'Content-Type: text/xml';
//add the raw post data
$httpRequest_OBJ->setRawPostData ($theData);
//send the http request
$result = $httpRequest_OBJ->send();
//print out the result
echo "<pre>"; print_r($result); echo "</pre>";
?>
when i consume wsdl i use cURL
for modifying headers and Envelopes use this:
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapenvelope);

php5 SOAP client developing identical tags

I am trying to generate a SOAP XML request that looks something like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="dto" xmlns:com="">
<soapenv:Header>
<dto:AuthenticationDTO>
<dto:LOGIN_ID>login</dto:LOGIN_ID>
<dto:LOGIN_PASSWORD>login</dto:LOGIN_PASSWORD>
</dto:AuthenticationDTO>
</soapenv:Header>
<soapenv:Body>
<com:createAccount>
<com:AccountFields>
<!--Zero or more repetitions:-->
<dto:FieldDTO>
<!--Optional:-->
<dto:children/>
<!--Optional:-->
<dto:fieldType>GENERAL</dto:fieldType>
<!--Optional:-->
<dto:index>0</dto:index>
<!--Optional:-->
<dto:label>BusinessName</dto:label>
<!--Optional:-->
<dto:name>BizInfo-BusinessName</dto:name>
<!--Optional:-->
<dto:value>the business name</dto:value>
</dto:FieldDTO>
<!--Zero or more repetitions:-->
<dto:FieldDTO>
<!--Optional:-->
<dto:children/>
<!--Optional:-->
<dto:fieldType>GENERAL</dto:fieldType>
<!--Optional:-->
<dto:index>0</dto:index>
<!--Optional:-->
<dto:label>BusinessCountry</dto:label>
<!--Optional:-->
<dto:name>BizInfo-Country</dto:name>
<!--Optional:-->
<dto:value>US</dto:value>
</dto:FieldDTO>
</com:AccountFields>
<com:ApplicationNumber></com:ApplicationNumber>
<com:CreditTerms></com:CreditTerms>
<com:GenerateAccountIdIndicator>true</com:GenerateAccountIdIndicator>
</com:createAccount>
I get a response using this code:
$matchCompany->FieldList->FieldDTO->fieldType = 'GENERAL';
$matchCompany->FieldList->FieldDTO->label = 'Business Name';
$matchCompany->FieldList->FieldDTO->name = 'BizInfo-BusinessName';
$matchCompany->FieldList->FieldDTO->index = '0';
try
{
$result = $soapClient->getAccountInfo($matchCompany);
print "<pre>";
print_r($result);
print "</pre>";
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
catch(SoapFault $fault)
{
echo $fault->faultcode . "-" . $fault->faultstring;
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
but if I try to array the fielddto item like this:
//$matchCompany->FieldList->FieldDTO[]['fieldType'] = 'GENERAL';
//$matchCompany->FieldList->FieldDTO[]['label'] = 'Business Name';
//$matchCompany->FieldList->FieldDTO[]['name'] = 'BizInfo-BusinessName';
//$matchCompany->FieldList->FieldDTO[]['index'] = '0';
It wraps each item in it's own FieldDTO tag instead of placing all four items in a single FieldDTO tag.
What am I missing? It seems like it should work, but it's not quite right.
Note that every time you execute $matchCompany->FieldList->FieldDTO[]['any_field'] the index of the array is increased by one. You could use a defined and manually incremented index (e.g. $matchCompany->FieldList->FieldDTO[$i]['any_field'] = 'any_value') or simply set all the values at once:
$matchCompany->FieldList->FieldDTO[] = array(
'fieldType' => 'GENERAL',
'label' => 'Business Name',
'name' => 'BizInfo-BusinessName',
'index' => '0'
);

Categories