WSDL Client Problem With PHP - 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);

Related

how to connect soap request to php request

below I have attached my soapui request. When I use this PHP code, getting response from the soapui is not working. Please help me find a solution
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-17855236" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>WSBENZTRAVELS</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">p#ss1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body xmlns:ns2="http://www.opentravel.org/OTA/2003/05">
<ns2:OTA_AirAvailRQ EchoToken='11868765275150-1300257933' PrimaryLangID='en-us' SequenceNmbr='1' Target='LIVE' TimeStamp='2018-10-08T11:39:35' Version='20061.00'><ns2:POS><ns2:Source TerminalID='Farhath/Farhath'><ns2:RequestorID ID='WSBENZTRAVELS' Type='4' /><ns2:BookingChannel Type='12' /></ns2:Source></ns2:POS><ns2:OriginDestinationInformation><ns2:DepartureDateTime>2018-10-30T00:00:00</ns2:DepartureDateTime><ns2:OriginLocation LocationCode='CMB' /><ns2:DestinationLocation LocationCode='RUH' /></ns2:OriginDestinationInformation><ns2:OriginDestinationInformation><ns2:DepartureDateTime>2018-11-30T00:00:00</ns2:DepartureDateTime><ns2:OriginLocation LocationCode='RUH' /><ns2:DestinationLocation LocationCode='CMB' /></ns2:OriginDestinationInformation><ns2:TravelerInfoSummary><ns2:AirTravelerAvail><ns2:PassengerTypeQuantity Code='ADT' Quantity='1' /></ns2:AirTravelerAvail></ns2:TravelerInfoSummary></ns2:OTA_AirAvailRQ>
</soap:Body>
</soap:Envelope>

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.

PHP Complexe Header with SoapClient()

I need to send Soap requests, but the server needs complex authentification and I don't no how create this header...
Target Soap structure :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://www.gmc.net/Phoenix/Integration">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>user</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<int:ListTicketsRequest>
<int:Company>test</int:Company>
</int:ListTicketsRequest>
</soapenv:Body>
</soapenv:Envelope>
My Php code
<?php
try
{
$wsdl = "https://aaa.wsdl";
$client = new SoapClient($wsdl, array('trace' => 1));
$header_part = '
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>user</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
';
$soap_var_header = new SoapVar( $header_part, XSD_ANYXML, null, null, null );
$soap_header = new SoapHeader( 'http://your-target-service.com', 'wsse', $soap_var_header );
$client->__setSoapHeaders($soap_header);
$res = $client->ListTickets(array('Company' => 'test'));
}
catch (SoapFault $fault)
{
echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring}) \n \n";
echo "====== REQUEST HEADERS =====" . PHP_EOL;
var_dump($client->__getLastRequestHeaders());
echo "========= REQUEST ==========" . PHP_EOL;
var_dump($client->__getLastRequest());
}
?>
My result
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.gmc.net/Phoenix/Integration" xmlns:ns2="http://your-target-service.com">
<SOAP-ENV:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>user</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ListTicketsRequest>
<ns1:Company>test</ns1:Company>
</ns1:ListTicketsRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Problems, Function SoapHeader need in first $data here 'http://your-target-service.com' (for testing). But my strucure include in native xmlns:ns1
Maybe my all my code is wrong..
I need your help !!
Thanks :)

php Soap client issue (Security header)

Uncaught SoapFault exception: [wsse:InvalidSecurity] Missing wsse:Security header in request
Can someone help me to solve this issue.What this error about??
<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="sample"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>sample</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<getHello xmlns="http://www.oracle.com"/>
</soap:Body>
</soap:Envelope>
Thanks.
This is common structure with two usertokens, you may need to use one.
<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="sample"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>sample</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<wsse:Security soap:actor="oracle"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken wsu:Id="oracle"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
<wsse:Username>oracle</wsse:Username>
<wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
<wsu:Created>2004-05-19T08:46:04Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<getHello xmlns="http://www.oracle.com"/>
</soap:Body>
</soap:Envelope>
You need to modify your request to this format.

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);

Categories