SOAP envelope with header authentication call php - 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

Related

How can i parse below xml by php?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
<ns0:getListValues>
<ns0:Person_ID>PPL000000301739</ns0:Person_ID>
<ns0:Submitter>soehler</ns0:Submitter>
<ns0:Profile_Status>Enabled</ns0:Profile_Status>
<ns0:Locale2>en_US</ns0:Locale2>
<ns0:VIP>No</ns0:VIP>
<ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
</ns0:getListValues>
</ns0:GetListBy_QualificationResponse>
</soapenv:Body>
</soapenv:Envelope>
Use Simple HTML Dom class. for example:
include('simple_html_dom.php');
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
<ns0:getListValues>
<ns0:Person_ID>PPL000000301739</ns0:Person_ID>
<ns0:Submitter>soehler</ns0:Submitter>
<ns0:Profile_Status>Enabled</ns0:Profile_Status>
<ns0:Locale2>en_US</ns0:Locale2>
<ns0:VIP>No</ns0:VIP>
<ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
</ns0:getListValues>
</ns0:GetListBy_QualificationResponse>
</soapenv:Body>
</soapenv:Envelope>';
$xml = str_get_html($xml);
print_r( $xml );
Read class documents and extract data from $xml variable.

Soap PHP : double XML tag

Hye
I'm trying to use a WebService with SOAP in PHP. But the SoapVar creates my DOM XML with double XML tag
My code :
$xmlContent = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:com="http://schemas.datacontract.org/2004/07/Commun.Metier">
<soapenv:Header/>
<soapenv:Body>
<tem:SendData> ....';
$soapClient = new SoapClient("URL OF THE WSDL", array('trace' => 1, 'location' => 'URL OF THE SERVICE', 'uri' => 'URL OF THE SERVICE'));
$myXML = new SoapVar($xmlContent, XSD_ANYXML);
try {
$result = $soapClient->__soapCall("SendData", array('SendData' => $myXML));
} catch (Exception $e) {
var_dump($e);
}
The problem is that I have an exception Bad request because the XML I'm sending haves 2 XML tags and Soap Enveloppe :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body><?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:com="http://schemas.datacontract.org/2004/07/Commun.Metier">
<soapenv:Header/>
<soapenv:Body>
<tem:SendData>
How can I cancel this double tag ?
Thanks

How to make a SOAP call in 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);

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\

how to parsing SOAP Response in PHP?

I just started with web service using SOAP.
I using below code to get response.
$response = $objClient->__getLastResponse();
My response is:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getHotelValuedAvail xsi:type="xsd:string" xmlns:ns1="http://axis.frontend.hydra.hotelbeds.com">
<HotelValuedAvailRS xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" timeToExpiration="1771163" totalItems="387" echoToken="DummyEchoToken">
<PaginationData currentPage="1" totalPages="387"/>
<ServiceHotel xsi:type="ServiceHotel" availToken="ngQXOz+UOoLDtPieFMhu9wdw">
<DateFrom date="20130709"/>
<DateTo date="20130711"/>
<Currency code="EUR">Euro</Currency>
<HotelInfo xsi:type="ProductHotel">
<Code>99361</Code>
<Name>Hilton Sa Torre Mallorca Resort</Name>
<Position latitude="39.42761529999999936535" longitude="2.75602390000000019299"/>
</HotelInfo>
</ServiceHotel>
</HotelValuedAvailRS>
</ns1:getHotelValuedAvail>
</soapenv:Body>
</soapenv:Envelope>
Can some one help me to get the value of Name Element?
I have tried simplexml_load_string($response) and and X-Path("/Name"), but i could not get it.
You can try using DOMDocument::getElementsByTagName :
You can try like this:
$response = $objClient->__getLastResponse();
$doc = new DOMDocument();
$doc->loadXML($response);
$names= $doc->getElementsByTagName( "Name" );
$name = $names->item(0)->nodeValue;
var_export( $name );

Categories