I need to access user name and password from the soap header inside php script. I can access the body information but could not access the header information.
Here is the SOAp...
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://schemas.xmlsoap.org/ws/2002/04/secext"
xmlns:met="http://www.example.com/data">
<soapenv:Header>
<sec:Security>
<UsernameToken>
<Username>ron</Username>
<Password>pass</Password>
</UsernameToken>
</sec:Security>
</soapenv:Header>
<soapenv:Body>
<met:columnInfo>
<databaseName>MySQL</adaptorName>
<tableName>product</tableName>
</met:columnInfo>
</soapenv:Body>
</soapenv:Envelope>
Any help will be really appreciated.
Ok found the solution for that.
$server = new SoapServer($anywsdl);
$server->addFunction(addAllFuntions);
$server->handle();
Then in the same php script,
function Security($data){
$UserToken=get_object_vars($data);
foreach($UserToken as $uToken){
$credentialArray=get_object_vars($uToken);
echo $credentialArray['Username'];
echo $credentialArray['Password'];
}
}
You would need $server->setClass($yourClass), if the Security() function was in different class.
Related
Hi i have this WSDL that, when i test in soapUI, it works well.
but i am having problems to call it from php soap client.
<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:urn="urn:uXXX">
<soapenv:Header/>
<soapenv:Body>
<urn:Pesquisar soapenv:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/">
<active xsi:type="xsd:boolean">true</active>
</urn:Pesquisar>
</soapenv:Body>
</soapenv:Envelope>
i am trying in PHP something like this:
$client = new \SoapClient($mywsdl);
$headers[] = new \SoapHeader('urn:uXXX', 'urn');
$client->__setSoapHeaders($headers);
var_dump($client->Pesquisar(['parameters'=>['active' => true]]));
PS: This soap, doens have authentication, because i am inside a server that have access to the soap server.
When using the ebay API, it make notification requests to your server which can look something like this:
<?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:Header>
Stuff in header
</soapenv:Header>
<soapenv:Body>
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2015-02-22T16:19:51.956Z</Timestamp>
<Ack>Success</Ack>
<CorrelationID>3759873</CorrelationID>
<Version>885</Version>
<Build>E885_CORE_APIMSG_16971418_R1</Build>
<NotificationEventName>ItemRevised</NotificationEventName>
.
.
</GetItemResponse>
</soapenv:Body>
</soapenv:Envelope>
I define a function GetItemResponse then register it with the SOAP server object $server->addFunction("GetItemResponse");. The problem is that the function only gets passed the first element '' as the first argument. How do I get the full body passed to my function?
Try converting the result to XML object like below:
$xml = simplexml_load_string($response);
and pass $xml
Try this:
function GetItem($arg1, $arg2, $arg3){
var_dump(func_get_args());
}
$soapServer->addFunction('GetItem')
GetItemResponse is node name that holds a response to GetItem call. Also you should add more parameters to GetItem function if you need them.
More information about parameters: http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/GetItem.html
If you really need full body then override handle method from SoapServer. It will allow you to get whole body.
I need to send a soap request with soap header and body.
I have the request soap xml.
I had use different curl and soap client but nothing is working.
Some one please help.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://www.v.com/schema/" xmlns:loc="http://www.c.org/local">
<soapenv:Header>
<RequestSOAPHeader xmlns="http://www.h.com/schema/1">
<s1>000201</s1>
<s2>e6434ef249df55c7a21a0b45758a39bb</s2>
<s3>35000001000001</s3>
<s4>20100731064245</s4>
</RequestSOAPHeader>
</soapenv:Header>
<soapenv:Body>
<loc:start>
<loc:reference>
<c1>http://desertcreator.com/nct</c1>
<c2>notify</c2>
<c3>1</c3>
</loc:reference>
<loc:w1>1234</loc:w1>
<loc:w2>demand</loc:w2>
</loc:start>
</soapenv:Body>
</soapenv:Envelope>
Thanks
I try to use some SOAP.
Here is what I have with SoapUI.
I Have to give Username,Password. But I dont know when I should put it.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:mob="http://schemas.datacontract.org/2004/07/Mobilog.Serveur.API.DTO.ParamRetour" xmlns:mob1="http://schemas.datacontract.org/2004/07/Mobilog.Serveur.API.DTO.ParamRetour.Dossiers3CE" xmlns:mob2="http://schemas.datacontract.org/2004/07/Mobilog.Serveur.API.DTO.Dossiers3CE">
<soapenv:Header/>
<soapenv:Body>
<tem:SaveDossier3CE>
<!--Optional:-->
<tem:paramSaveDossier3CE>
<!--Optional:-->
<mob:Authentification>?</mob:Authentification>
<!--Optional:-->
<mob:Origine>?</mob:Origine>
<!--Optional:-->
<mob:Password>?</mob:Password>
<!--Optional:-->
<mob:Username>?</mob:Username>
<mob:CodeUsr>?</mob:CodeUsr>
<!--Optional:-->
<?php
$soap = new SoapClient("file.wsdl");
$soap->SaveDossier3CE();
?>
Where Should I put the "Password / Origine" var ? I tried something like this :
<?php
$soap->SaveDossier3CE(array('username'=>'blabla'));
?>
Didnt work.
Any idea?
Usually they are sent as parameters to the function call.
$soap->SaveDossier3CE($username,$password);
As you seem to have access to the WSDL, I would advise you to try to generate the corresponding PHP classes that will show you how to easily send this sort of request.
I strongly advise you to use a WSDL to PHP generator such as PackageGenerator
I'm having a problem in order to create a soap call. As one can see the header that is being supplied from a 3rd party client doesn't have a header name. I need to create a soap call by passing the username and password to the soap request which doesn't have a name in the header. I have tried several examples but no success. The call below works in soap UI but I'm having serious problems when it comes to php. Any help would be much appreciated
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>
Please take a look at http://php.net/manual/en/soapclient.dorequest.php
You can use code like:
$response = $soapClient->__doRequest(
$request,
$endpoint,
$soapAction,
$soapVersion,
$one_way
);
$request could be defined as a string containing xml, such as:
$request =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/""xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>';
You can define the rest of the arguments in the __doRequest() call depending on your configuration.