Webservice SOAP php - php

I need some help
I have to connect a SOAP webservice, using PHP
I have the service, something like this:
http://xxx/xxx/Servicios?wsdl (real url is hidden)
I have an user and password for this
A method is implemented (by other team), SelectLectores, and request is something like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://xxxxxxxxx">
<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">
<wsse:Username>myuser</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<impl:selectLectores>
<arg0>
<!--Mandatory:-->
<centro>51000286</centro>
<!--Optional:-->
<codigoLector>14103</codigoLector>
</arg0>
</impl:selectLectores>
</soapenv:Body>
</soapenv:Envelope>
Im using this code to connect in php:
$service="http://xxx/xxx/Servicios?wsdl";
$param=array();
$param['centro']=51000286;
$validation= array(
'Username' => 'myuser',
'Password' => 'mypassword'
);
$client = new SoapClient($service,$validation);
$result = $client->selectLectores($param);
But doesn´t work, shows this error:
500 | Internal Server Error | SoapFault
java.lang.NullPointerException
Im doing something wrong?

Related

ns1:FailedAuthenticationThe security token could not be authenticated or authorized

here is my xml code for authentication:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:esf="esf">
<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 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>my_username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">my_password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<esf:createSessionRequest>
<tin>my_bin</tin>
<x509Certificate>my_cert</x509Certificate>
</esf:createSessionRequest>
</soapenv:Body>
</soapenv:Envelope>
there is connection to site
try{ $CreateSession = $SessionService>__doRequest
($Create_session_xml, 'https://esf.gov.kz:8443/esfweb/ws/SessionService wsdl', '', SOAP_1_2);
echo $CreateSession;// here I get error: FailedAuthenticationThe security token could not be authenticated or authorized
} catch(SoapFault $e){
echo "Error: ".$e->getMessage().PHP_EOL;
}
I registered on this site, checked it. So problems with my datas no.
is there any idea? please help, I searched through internet, no results.
Edit: Initialization of the soap client taken from the comments.
$SessionService = new SoapClient(NULL, [
"location" => "esf.gov.kz:8443/esf-web/ws/SessionService",
"uri" => "esf-test.kgd.gov.kz:9443",
"style" => SOAP_DOCUMENT,
"use" => SOAP_LITERAL,
"stream_context" => $context
]);

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 make a php SOAP call

I am having trouble setting the body of a PHP SOAP call. I believe I am close just dont know how to get it in the correct format.
Here is what I have thus far in PHP
$client = new SoapClient('http://url');
$username='username';
$password='password';
$headers='
'.$username.'
'.$password.'
';
$securityTags = new SoapVar($headers, XSD_ANYXML);
$header=new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security",$securityTags,true);
$client->__setSoapHeaders(array($header));
//HOW DO I SET THE BODY????
$params = array('deal'=>'PT10M', 'StoreIds'=>64);
return $client->__soapCall("PullDeals", array('searchCriteria'=>$params));
Below is what the request should look like
<soapenv:Envelope xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:deal="http://url.com" xmlns:ns="http://url" 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 wsu:Id="UsernameToken-145" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>YOUR_USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">YOUR_PASSWORD</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JQT6P7Zd3COZerXkREww2g==</wsse:Nonce>
<wsu:Created>2013-11-19T22:18:54.122Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ns:PullDeals>
<ns:searchCriteria>
<deal:MaxElapsedSinceUpdate>PT10M</deal:MaxElapsedSinceUpdate>
<deal:StoreIds><arr:long>64</arr:long></deal:StoreIds>
</ns:searchCriteria>
</ns:PullDeals>
</soapenv:Body>
</soapenv:Envelope>
To compare your request to the what the request should look like add 'trace' => true to your soap client.
$client = new SoapClient("my.wsdl", array('trace' => true));
and then use echo $client->__getLastRequest(); to spit out the XML.
I usually just view it on the page with chrome's Inspector to see it nicely indented.
You can reformat your call accordingly after you see how it is being formed.
Failing that you can hard code the XML.

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

Categories