Soap Php Example - php

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

Related

How to figure out Arguments for __soapCall()

Im trying to access a specific method from a webservice. i can access the webservice, i know because __getFunctions() is working. What i need to know is which arguments i have to pass, to call getItem(). In SoapUI a request looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://webservice.mks.com/2009/Integrity" xmlns:sch="http://webservice.mks.com/2009/Integrity/schema">
<soapenv:Header/>
<soapenv:Body>
<int:getItem>
<!--Optional:-->
<arg0 transactionId="?" sch:ItemId="8720303">
<sch:Username>--</sch:Username>
<sch:Password>--</sch:Password>
<sch:InputField>State</sch:InputField>
</arg0>
</int:getItem>
</soapenv:Body>
</soapenv:Envelope>
I think i have to pass a ItemId, Username, Password and InputField. But i have no Idea in which way i have to. I am using php and i called the method like this:
$result = $client->__soapCall('getItem',array('arg0'=>array('transactionId'=>'?','ItemId'=>'8720303','InputField'=>'State', 'Username'=>'--','Password'=>'--')));

How to receive soap request from codeigniter controller?

How I can receive a soap request in my controller? For your convenient I am sharing the sample soap format. From this I need to get "message" field. Can you please suggest me any solution.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:NotifySOAPHeader xmlns:ns1="http://www.huawei.com.cn/schema/common/v2_1">
<ns1:timeStamp>111029084631570</ns1:timeStamp> <ns1:traceUniqueID>100001200101110623021721000011</ns1:traceUniqueID>
</ns1:NotifySOAPHeader>
</soapenv:Header>
<soapenv:Body>
<ns2:notifySmsReception xmlns:ns2="http://www.csapi.org/schema/parlayx/sms/notification/v2_2/local">
<ns2:correlator>00001</ns2:correlator>
<ns2:message>
<message>Hello world</message>
<dateTime>2010-08-09T00:00:00.000+08:00</dateTime>
</ns2:message>
</ns2:notifySmsReception>
</soapenv:Body>
</soapenv:Envelope>

How to call Soap Client PHP with urn?

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.

Access credential information from soap header in PHP

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.

Soap header without header name php

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.

Categories