Build SOAP header - php

i need use a SOAP webservice for a project.
The webservice requires authentication via a SOAP header like this:
<soap:Header>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>STAGING_WS</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">ANDREANI</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
So, i tried build the headers using SoapHeader class as below:
$ns = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$auth = new \StdClass();
$auth->Username = new \SoapVar('STAGING_WS', XSD_STRING, NULL, $ns, NULL, $ns);
$auth->Password = new \SoapVar('ANDREANI', XSD_STRING, NULL, $ns, NULL, $ns);
$token = new \StdClass();
$token->UsernameToken = new \SoapVar($auth, SOAP_ENC_OBJECT, NULL, $ns, 'UsernameToken', $ns);
$security = new \SoapVar(new \SoapVar($token, SOAP_ENC_OBJECT, NULL, $ns, 'UsernameToken', $ns), SOAP_ENC_OBJECT, NULL, $ns, 'Security', $ns);
$header = new \SoapHeader('wsse', 'Security', $security, true);
But, the generatd header is not equal:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.andreani.com.ar" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns3="wsse">
<env:Header>
<ns3:Security env:mustUnderstand="true">
<ns2:UsernameToken>
<ns2:Username>STAGING_WS</ns2:Username>
<ns2:Password>ANDREANI</ns2:Password>
</ns2:UsernameToken>
</ns3:Security>
</env:Header>
<env:Body>
<ns1:ConfirmarCompra/>
</env:Body>
</env:Envelope>
Any ideas ?

Try changing the last line to:
$header = new \SoapHeader($ns, 'Security', $security, true);
This will make the namespace of the Security tag to be the same as UsernameToken, Username and Password tags. The local name for the security namespace will be still ns2 and not wsse but that doesn't really matter. The correct SOAP Server must accept it as long as the namespace url is correct.

Related

To generate webservice token header with PHP and SOAP

I'm trying to consume a service from a webservice that asks for authentication, but I can not generate the Timestamp and UsernameToken.
<wsu:Timestamp wsu:Id="TS-1C1ABE5282FC96252314981531909334">
<wsse:UsernameToken wsu:Id="UsernameToken-1C1ABE5282FC96252314981531792593">
Send Corret:
<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"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Timestamp wsu:Id="TS-1C1ABE5282FC96252314981531909334">
<wsu:Created>2017-07-20T22:07:01.999Z</wsu:Created>
<wsu:Expires>2017-07-20T22:10:01.999Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-1C1ABE5282FC96252314981531792593">
<wsse:Username>xxxxxxxxxxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">nrg2241zhN8HMAn1bg7OLCL/6eM=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">ODgwODIzNDMz</wsse:Nonce>
<wsu:Created>2017-07-20T22:07:01.999Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
I'm using the function below:
/**
* This function implements a WS-Security authentication for PHP.
*
* #access private
* #param string $user
* #param string $password
* #return SoapHeader
*/
function soapClientWSSecurityHeader($user, $password)
{
// Creating date using yyyy-mm-ddThh:mm:ssZ format
$tm_created = gmdate('Y-m-d\TH:i:s\Z');
$tm_expires = gmdate('Y-m-d\TH:i:s\Z', gmdate('U') + 180); //only necessary if using the timestamp element
// Generating and encoding a random number
$simple_nonce = mt_rand();
$encoded_nonce = base64_encode($simple_nonce);
// Compiling WSS string
$passdigest = base64_encode(sha1($simple_nonce . $tm_created . $password, true));
// Initializing namespaces
$ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$ns_wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
$password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
$encoding_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
// Creating WSS identification header using SimpleXML
$root = new SimpleXMLElement('<root/>');
$security = $root->addChild('wsse:Security', null, $ns_wsse);
//the timestamp element is not required by all servers
$timestamp = $security->addChild('wsu:Timestamp', null, $ns_wsu);
$timestamp->addAttribute('wsu:Id', 'Timestamp-28');
$timestamp->addChild('wsu:Created', $tm_created, $ns_wsu);
$timestamp->addChild('wsu:Expires', $tm_expires, $ns_wsu);
$usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
$usernameToken->addChild('wsse:Username', $user, $ns_wsse);
$usernameToken->addChild('wsse:Password', $password, $ns_wsse)->addAttribute('Type', $password_type);
$usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
$usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);
// Recovering XML value from that object
$root->registerXPathNamespace('wsse', $ns_wsse);
$full = $root->xpath('/root/wsse:Security');
$auth = $full[0]->asXML();
return new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true);
}
My return using the above function:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
Id="Timestamp-28">
<wsu:Created>2017-07-20T22:18:53Z</wsu:Created>
<wsu:Expires>2017-07-20T22:21:53Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken>
<wsse:Username>XXXXXXXXXXXXXXXXXXX</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
XXXXXXXXXXXXXXXXXX
</wsse:Password>
<wsse:Nonce
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">
OTUxOTA4NDYz
</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
2017-07-20T22:18:53Z
</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
These two tokens need to be generated, but with this function they are not.
You should try usine the WsSecurity project from Github that handles this sort of thing by facilitating the soap header construction and its inclusion on your soap request

Complex Headers for PHP SoapClient

I need to add the following complex header with different namespace and types to my SoapClient Header.
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>****</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action>/IntS5/S5WS</wsa:Action>
</soapenv:Header>
As proposed in other answers I tried the following approach in my php project.Since I need WSA Addressing, I set the wsa:Action with security header together.
$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" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'
. '<wsse:UsernameToken><wsse:Username>****</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password>'
. '</wsse:UsernameToken></wsse:Security><wsa:Action>/IntS5/S5WS</wsa:Action>';
$soap_var_header = new SoapVar($header_part, XSD_ANYXML, null, null, null);
$soap_header = new SOAPHeader('http://www.w3.org/2005/08/addressing', 'wsa', $soap_var_header);
$client->__setSoapHeaders($soap_header);
Some how __soapCall returns me the following error.
SoapFault exception: [Client] DTD are not supported by SOAP.I am not sure if it's related to header or the parameters of the putCall. Anybody can help me ?
EDIT: The problem is probably related with the namespace of the HEADER/Envelope.
The request which is sent to server looks like this.
UPDATED
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://ws.s5.mediasat.de/" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>****</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">/IntS5/S5WS</wsa:Action>
</env:Header>
<env:Body>
<ns1:putCall>
<transaction>createIncident</transaction>
<transactionSender>Request</transactionSender>
<caseDataModel>
<senderId>7</senderId>
<ticketTypeId>102</ticketTypeId>
<title>test</title>
<priorityId>101</priorityId>
<categoryId>128</categoryId>
<description>Description</description>
<ticketNumberSender>INCC00000743809</ticketNumberSender>
<createTypeId>701</createTypeId>
<serviceId>B001APP05K</serviceId>
<categoryId>128</categoryId>
<serviceRecipientId>77888</serviceRecipientId>
<serviceLocationSAPCode>V135</serviceLocationSAPCode>
</caseDataModel>
</ns1:putCall>
</env:Body>
</env:Envelope>
The request that works on SOAP UI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.s5.mediasat.de/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>***</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">***</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action>/IntS5/S5WS</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ws:putCall>
<transaction>createIncident</transaction>
<transactionSender>Request</transactionSender>
<caseDataModel>
<senderId>7</senderId>
<ticketTypeId>102</ticketTypeId>
<title>test</title>
<priorityId>101</priorityId>
<categoryId>128</categoryId>
<description>Description</description>
<ticketNumberSender>INCC00000743809</ticketNumberSender>
<createTypeId>701</createTypeId>
<serviceId>B001APP05K</serviceId>
<categoryId>128</categoryId>
<serviceRecipientId>77888</serviceRecipientId>
<serviceLocationSAPCode>V135</serviceLocationSAPCode>
</caseDataModel>
</ws:putCall>
</soapenv:Body>
</soapenv:Envelope>
Is there anyway to set/override the namespace for the header?
You should generate the header procedurally instead of using the string.
Example:
<?php
$client = new SoapClient(null, array(
'location' => "http://localhost/soap/",
'uri' => "http://ws.s5.mediasat.de/",
'soap_version' => SOAP_1_2
));
$username = '***';
$password = '***';
$sec_namespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
// prepare security token
$node1 = new \SoapVar($username, XSD_STRING, null, null, 'Username', $sec_namespace);
$xml = new XMLWriter(); // this is a little hacky, but no other way to set the type as far as I know
$xml->openMemory();
$xml->startElementNS('wsse', 'Password',$sec_namespace);
$xml->writeAttribute('Type', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText');
$xml->Text($password);
$xml->endElement();
$node2 = new \SoapVar($xml->outputMemory(), XSD_ANYXML);
$token = new \SoapVar(array($node1, $node2), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $sec_namespace);
$security = new \SoapVar(array($token), SOAP_ENC_OBJECT, null, null, 'Security', $sec_namespace);
$soap_header_sec = new \SOAPHeader($sec_namespace, 'Security', $security, true);
// prepare action token
$action = new \SoapVar('/IntS5/S5WS', XSD_STRING, null, null, 'Action', $wsa_namespace);
$soap_header_action = new \SOAPHeader($wsa_namespace, 'Action', $action, false);
// set prepared headers
$client->__setSoapHeaders(
[$soap_header_sec,$soap_header_action]
);
$client->putCall();
This will produce the valid envelope with all namespaces set:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://ws.s5.mediasat.de/" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Header>
<ns2:Security env:mustUnderstand="true">
<ns2:UsernameToken>
<ns2:Username>***</ns2:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">***</wsse:Password>
</ns2:UsernameToken>
</ns2:Security>
<ns3:Action>/IntS5/S5WS</ns3:Action>
</env:Header>
<env:Body>
<ns1:putCall env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
</env:Body>
</env:Envelope>
The name space "http://www.w3.org/2005/08/addressing" is not bound to the prefix "wsa".
The "mustUnderstand" attribute must use the prefix "env" not "soapenv".
You can declare the missing namespace locally. You just have to fix you header_part to look like this:
header_part = '<wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'
. '<wsse:UsernameToken><wsse:Username>****</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password>'
. '</wsse:UsernameToken></wsse:Security><wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">/IntS5/S5WS</wsa:Action>';
Note: Maybe it is obvious but it is kind of dangerous to assume that the prefix for the "http://www.w3.org/2003/05/soap-envelope" will always be "env". The framework can change this at any time. If you want to be on the really safe side you might prefer to bind the namespace locally to a new prefix:
<wsse:Security soapenv:mustUnderstand="1" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" ...
But having one namespace bound to two different prefixes will make things even harder to read and understand so I would say it is a question of taste.

PHP > SOAP created Attributes in header "The Correct way"

I am facing an issue with SOAP Header in PHP
My code should generate something like this
<soapenv:Header>
<ns1:RequestHeader xmlns:ns1="xxxxxxx">
<ns1:auth xmlns:ns1="yyyy">
<ns1:user>xxx</ns1:user>
<ns1:pass>false</ns1:pass>
</ns1:auth>
</ns1:RequestHeader>
</soapenv:Header>
The issue, I can't figure out how to do it correctly and I found many tricks to do it but most of them will force me either to change how I send the main XML or change my entire code.
My current code print the following
<soapenv:Header>
<ns1:RequestHeader>
<ns1:auth>
<ns1:user>xxx</ns1:user>
<ns1:pass>false</ns1:pass>
</ns1:auth>
</ns1:RequestHeader>
</soapenv:Header>
and my code is
$Auth = new stdClass();
$Auth->auth->user = "user";
$Auth->auth->pass = "pass";
$header = new SoapHeader(true,'RequestHeader',$Auth,false);
$client->__setSoapHeaders($header);
What do you think about this, how can I add Attributes correctrly to RequestHeader?
Thanks
I found the solution for that,
$header_part = '
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext" SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>'."USERNAME".'</wsse:Username>
<wsse:Password>'."PASSWORD".'</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 );
$soap_client->__setSoapHeaders($soap_header);
you need to send this with the original soap request.

Php SOAP Client building request

I wanna build a request with php soap client.
The provider sent us a sample request.
here is my code;
$client = new SoapClient('http://myurl.com/TrevooWS.svc?wsdl' , array('trace' => true, 'exception' => false));
$auth_ns = 'http://schemas.datacontract.org/2004/07/Trevoo.WS.Entities.Authentication.IO';
$base_ns = 'http://schemas.datacontract.org/2004/07/Trevoo.WS.Entities.Base';
$object = new stdClass();
$form = new stdClass();
$form->Username = new SoapVar( 'USER' , XSD_STRING , null , null, 'trev1', $auth_ns);
$form->Password = new SoapVar( 'PASS' , XSD_STRING , null , null, 'trev1', $auth_ns);
$form->IsTestMode = new SoapVar( 1 , XSD_INTEGER, null , null, 'trev1', $auth_ns);
$form->ClientName = new SoapVar( 'CLIENT' , XSD_STRING , null , null, 'trev1', $auth_ns);
$form->ClientIP = new SoapVar( '0' , XSD_STRING , null , null, 'trev1', $auth_ns);
$object->request = new stdClass();
$object->request->Form = new SoapVar($form , SOAP_ENC_OBJECT, null , null, 'tem', $base_ns);
$object->request->Form->enc_namens = $auth_ns;
$object->request->Form->enc_name = 'trev1';
$object->request->enc_namens = $base_ns;
$object->request->enc_name = 'tem';
try{
$result = $client->Login( $object );
var_dump($result);
} catch (SoapFault $e){
echo $e;
var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());
}
Expected request from provider. They sent this sample request.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:trev="http://schemas.datacontract.org/2004/07/Trevoo.WS.Entities.Base" xmlns:trev1="http://schemas.datacontract.org/2004/07/Trevoo.WS.Entities.Authentication.IO">
<soapenv:Header />
<soapenv:Body>
<tem:Login>
<tem:request>
<trev1:Form>
<trev1:ClientIP>0</trev1:ClientIP>
<trev1:ClientName>s</trev1:ClientName>
<trev1:IsTestMode>0</trev1:IsTestMode>
<trev1:Password>PASSWORD</trev1:Password>
<trev1:Username>USERNAME</trev1:Username>
</trev1:Form>
</tem:request>
</tem:Login>
</soapenv:Body>
</soapenv:Envelope>
What I get;
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.datacontract.org/2004/07/Trevoo.WS.Entities.Authentication.IO" xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
<ns2:Login>
<ns2:request>
<ns1:Form>
<ns1:Username>USERNAME</ns1:Username>
<ns1:Password>PASSWORD</ns1:Password>
<ns1:IsTestMode>1</ns1:IsTestMode>
<ns1:ClientName>CLIENT</ns1:ClientName>
<ns1:ClientIP>0</ns1:ClientIP>
</ns1:Form>
</ns2:request>
</ns2:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is response for Login method.
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
<faultstring xml:lang="tr-TR">String reference not set to an instance of a String.
Parameter name: s</faultstring>
<detail>
<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true" />
<InnerException i:nil="true" />
<Message>String reference not set to an instance of a String.
Parameter name: s</Message>
<StackTrace>at System.Text.Encoding.GetBytes(String s)
at Trevoo.Utilities.Crypto.MD5Hash(String input) in c:\Trevoo_TFS\*****\trunk\main\Trevoo\Projects\Core\Trevoo.Core\Utilities\Crypto.cs:line 131
at Trevoo.Accounts.AuthController.ReadonlyLogin(LoginRequest request) in c:\Trevoo_TFS\*****\trunk\main\Trevoo\Projects\Core\Trevoo.Core\Accounts\AuthController.cs:line 22
at Trevoo.Accounts.AuthController.Login(LoginRequest request) in c:\Trevoo_TFS\*****\trunk\main\Trevoo\Projects\Core\Trevoo.Core\Accounts\AuthController.cs:line 10
at Trevoo.WS.Services.Base.Login(T_LoginRequest request) in c:\Trevoo_TFS\*****\trunk\main\Trevoo\Projects\WS\Trevoo.WS\Services\Authentication\Login.cs:line 13
at SyncInvokeLogin(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
<Type>System.ArgumentNullException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
I couldnt see what is wrong. Could you help me?
you need to order elements as expected
Ordering must be;
->ClientIP
->ClientName
->IsTestMode
->Password
->Username

Add xmlns to SoapParam in PHP

I have the proper SOAP request being created except that I need the LogOn node to have an xmlns attribute. This is what the attribute looks like: xmlns="http://www.ultipro.com/dataservices/bidata/2". I have used SOAPUI to test the request and it appears that if I add that xmlns then the response should be a success.
Here is my current code:
function Login($username, $password, $clientaccesskey, $useraccesskey)
{
class LogOn
{
function __construct($request)
{
$this->logOnRequest = $request;
}
}
// Class handler for the request
class logOnRequest {
function __construct($usr, $pwd, $cak, $uak)
{
$this->UserName = $usr;
$this->Password = $pwd;
$this->ClientAccessKey = $cak;
$this->UserAccessKey = $uak;
}
}
// Conversion to a SOAP object
$lor = new LogOnRequest($username, $password, $clientaccesskey, $useraccesskey);
$lo = new LogOn($lor);
$logOnRequest = new SoapVar($lor, SOAP_ENC_OBJECT, 'logOnRequest');
$loi = new SoapVar($lo, SOAP_ENC_OBJECT);
$headers = array();
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn');
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://service4.ultipro.com/services/BiDataService');
try
{
$soapclient = new SoapClient('https://service4.ultipro.com/services/BiDataService', array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'exceptions' => TRUE, 'trace' => TRUE));
$soapclient->__setSoapHeaders($headers);
// Direct call to the LogOn method and SOAP parameter pass
$response = $soapclient->LogOn(new SoapParam($loi, 'LogOn'));
echo json_encode($response);
echo htmlentities($soapclient->__getLastRequest());
}
catch(SoapFault $fault){
echo $fault->faultstring;
}
}
This is what my request looks like:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.ultipro.com/dataservices/bidata/2" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action>http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</ns2:Action>
<ns2:To>https://service4.ultipro.com/services/BiDataService</ns2:To>
</env:Header>
<env:Body>
<ns1:LogOn>
<logOnRequest>
<UserName></UserName>
<Password></Password>
<ClientAccessKey></ClientAccessKey>
<UserAccessKey></UserAccessKey>
</logOnRequest>
</ns1:LogOn>
</env:Body>
</env:Envelope>
It needs to look like this:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.ultipro.com/dataservices/bidata/2" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action>http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</ns2:Action>
<ns2:To>https://service4.ultipro.com/services/BiDataService</ns2:To>
</env:Header>
<env:Body>
<ns1:LogOn xmlns="http://www.ultipro.com/dataservices/bidata/2">
<logOnRequest>
<UserName></UserName>
<Password></Password>
<ClientAccessKey></ClientAccessKey>
<UserAccessKey></UserAccessKey>
</logOnRequest>
</ns1:LogOn>
</env:Body>
</env:Envelope>

Categories