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
]);
Related
I am trying soap request with authentication. Wdsl server requiring user authentication. So i used SOAP header method.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.connector.uut.cs.com.tr/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>my_user_name</wsse:Username>
<wsse:Password>my_password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ser:sendInvoice>
<id>123456</id>
<type>INVOICE</type>
<invoiceNo>AAA123456001</invoiceNo>
<data></data>
<hash>dfa06b85d66ef786f9f091f38e09c184</hash>
<mimeType>application/xml</mimeType>
<version>1.0</version>
</ser:sendInvoice>
</soapenv:Body>
</soapenv:Envelope>
Php soap request:
$auth = array(
'Username' => 'my_user_name',
'Password' => 'my_password',
);
$url = 'https://test.com/ws/connectorService?wsdl';
try {
$request = new SoapClient( $url, $auth );
$header = new SOAPHeader( $url, 'Security', $auth );
$request->__setSoapHeaders( $header );
$result = $request->sendInvoice();
} catch( Exception $exc ) {
$result = $exc->getMessage();
}
The $result is printing "java.lang.NullPointerException".
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 :)
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?
I am getting desperate here, I am trying to convert an XML SOAP request which works in SoapUI to PHP. I went through so much documentation online and still cannot get to creating a correct request from within PHP. I tried using the SOAP class provided in PHP together SoapVars, SoapParams and SoapHeaders. This is the request I need to send (in XML form):
<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/03/addressing'
xmlns:gen='http://www.polaris-uk.co.uk/GenericSchema/1_1/GenericTypes'
xmlns:Detail='http://www.polaris-uk.co.uk/GenericSchema/2/PEMFault'
xsi:SchemaLocation='http://www.polaris-uk.co.uk/GenericSchema/2/PEMFault http://ppw.imarket.co.uk/Polaris/Schema/PEMFault.xsd'>
<soapenv:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis- 200401-wss-wssecurity-secext-1.0.xsd"
soapenv:mustUnderstand="1"
soapenv:actor="http://www.imarket.co.uk/soap/actor">
<wsse:UsernameToken>
<wsse:Username>XXXXXXXXXX</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ns2curity-secext-1.0.xsd#PasswordText">XXXXXXXXXX</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ConfirmImarketUserIDReq xmlns="http://www.polaris-uk.co.uk/Schema/1_1/ConfirmImarketUserIDReq">
<ns1:UserID xmlns:ns1="http://www.polaris-uk.co.uk/GenericSchema/1_1/GenericTypes">XXXXXXXXXX</ns1:UserID>
<ns2:Password xmlns:ns2="http://www.polaris-uk.co.uk/GenericSchema/1_1/GenericTypes">XXXXXXXXXX</ns2:Password>
</ConfirmImarketUserIDReq>
</soapenv:Body>
</soapenv:Envelope>
I will not post any code I did until now because it is just a mess since I tried writing bits and pieces without actually putting them together at one point and it will just spam this whole post.
Please, if anyone could help with converting this into a PHP code it will be much appreciated.
Thank you in advance!
After headaches over this, I finally found a working solution, might not be the best but it works by providing Raw XML to the SOAP call:
$wsdl = "XXXX.wsdl";
$client = new SoapClient($wsdl, array( 'soap_version' => SOAP_1_1,'trace' => true,));
//=========== Header Settings ============\\
//Namespace of the Web Service
$namespace = 'http://schemas.xmlsoap.org/soap/envelope/';
$headerXML = <<<XML
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
SOAP-ENV:mustUnderstand="1" SOAP-ENV:actor="http://www.imarket.co.uk/soap/actor">
<wsse:UsernameToken>
<wsse:Username>XXXXXX</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ns2curity-secext-1.0.xsd#PasswordText">XXXXXX</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
XML;
$headerObj = new SoapVar($headerXML, XSD_ANYXML, null, null, null);
$header = new SoapHeader($namespace , 'SessionHeader', $headerObj);
// More than one header can be provided in this array.
$client->__setSoapHeaders(array($header));
//============== Request ================\\
$xml = <<<XML
<ConfirmImarketUserIDReq xmlns="http://www.polaris-uk.co.uk/Schema/1_1/ConfirmImarketUserIDReq">
<ns1:UserID xmlns:ns1="http://www.polaris-uk.co.uk/GenericSchema/1_1/GenericTypes">XXXXXX</ns1:UserID>
<ns2:Password xmlns:ns2="http://www.polaris-uk.co.uk/GenericSchema/1_1/GenericTypes">XXXXXX</ns2:Password>
</ConfirmImarketUserIDReq>
XML;
$args = array(new SoapVar($xml, XSD_ANYXML));
try {
$response = $client->__soapCall( 'ConfirmImarketUserIDOp', $args);
var_dump($response);
}
catch (SoapFault $e) {
trigger_error("SOAP Fault: (faultcode: {$e->faultcode}, faultstring: {$e->faultstring})", E_USER_ERROR);
}
Hope this helps anyone,
Cheers!
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.