WSDL authentication - php

I am first time working with WSDL (no matter which coding language) and I am trying to call one api from it.
I have wsdl specification
https://testsportmidoffice.iedu.sk/Services/Sys/Codebook.svc?singleWsdl
I have username and password
And I have tried it multiple times, one of the tries:
$wsdl_codebook = "https://testsportmidoffice.iedu.sk/Services/Sys/Codebook.svc?singleWsdl";
$client_codebook = new SoapClient($wsdl_codebook, array("trace" => 1));
$header = new SoapHeader('http://tempuri.org/', 'AuthHeader', array('Login' => $auth_login, 'Password' => $auth_password));
$client_codebook->__setSoapHeaders($header);
$sportListParam = array (
'LanguageID' => 'sk'
);
$result = $client_codebook->__soapCall("GetSportList", $sportListParam);
Can someone help me why it's not working? Seems that this is an issue with authentication

Related

How can i get my PHP SoapClient to Authenticate with Digest

I currently have a vb.net ASMX web service hosted on IIS along with a PHP page which is calling the web service via a SoapClient.
I need to authenticate the webservice against ActiveDirectory and i figured the easiest way to do this would be to enable Digest Authentication on IIS and allow the user to enter their AD username/password into the PHP page and send this authentication in the SoapHeaders.
I am not really quite sure how to go about this, especially when trying to contact the WSDL (which is also behind the Digest Authentication).
Any help would be appreciated.
Thanks
EDIT: What i've tried:
SERVICE_URL points to http://mypage/service.asmx?wsdl
Attempt 1: User and Pass as MD5
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
Attempt 2: Auth is the 'user':'realm':'pass' as MD5:
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'login' => $_SESSION['auth']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
You can add headers to your soap client using SoapHeader() class/object (SoapHeader() documentation) and soap object operator __setSoapHeaders() (__setSoapHeaders() documentation).
Your request would look something like this:
<?php
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try {
$client = new SoapClient(SERVICE_URL, $options);
// create and populate header array
$headers = array();
$headers[] = new SoapHeader('MYNAMESPACE',
'authentication',
'SOAP_AUTHENTICATION_DIGEST');
$headers[] = new SoapHeader('MYNAMESPACE',
'realm',
'myrealm');
$client->__setSoapHeaders($headers); // set headers
$client->__soapCall("echoVoid", null); // make soap call
}
?>

PHP SOAP Client giving error at the time of calling a method "SoapFault exception: [s:Receiver] Object reference not set to an instance of an object"

I am completely new to PHP SOAP . After doing some R&D for my problem I got some links of stackoverflow but didn't get the perfect solution.
Here is my problem :
I am creating a SOAP client that will execute a method called GetPassword and It will return an encrypted password with response code '100' if the credentials is correct. In case of wrong credential a response code '101' and the response status will receive.
Here is my code (I am hiding the credentials for security purpose):
$url= "http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc?wsdl";
$method = "GetPassword";
$error=0;
$client = new SoapClient($url, array('soap_version' => SOAP_1_2 , 'SoapAction'=>'http://tempuri.org/IStarMFFileUploadService/GetPassword'));
$actionHeader= array();
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IStarMFFileUploadService/GetPassword');
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'To',
'http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc/Basic');
$client->__setSoapHeaders($actionHeader);
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
try{
$info = $client->__call($method, array($param));
}
catch (SoapFault $fault) {
$error = 1;
}
if($error==1) {
$xml=$fault;
}else{
$xml = $info;
}
echo($xml);
Some couples of days ago I got this error and the error was happening due to the mismatch of parameters. But this time I think the parameters are correct. So may be I am doing some small mistakes.. Please help me to find the mistakes.
If any input needed, please let me know in the comment, I will update.
Please Note : I tested the wsdl URL with the SoapUI software and it is returning perfectly.
The Problem was with Parameter . Just analyze the structure of the Method GetPassword and found that it take only one parameter named 'Param' which is an object and inside the Param object it is taking the values of MemberId', 'Password' , 'UserId'.
So just need to change one line of code.
use
$param =array ('Param' => array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX') );
Instead of
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
and the issue resolved.

PHP SoapClient "Body must be present in a SOAP envelope" error

I faced with very strange issue when tried to use PHP SoapClient for this service http://bws.neteven.com/NWS/2.
I have to setup an authentication header. Request body should be empty. The code, which I used is below:
$client = new SoapClient("http://bws.neteven.com/NWS/2", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
After that I used $client->__getLastRequest() to see what is final XML of the request. However I can see that the header and body params were not setup properly.
$client->__getLastRequest() outputs plain text like this:
MethodTestConnectionLoginloginSeedseedStampstampSignaturesignature
Which doesn't look like valid XML. So of course I get SoapFault exception with the text "Body must be present in a SOAP envelope".
Does anybody knows why header and body are not wrapped by required XML tags?
Any issue in the code? Because I saw lots of examples of PHP SoapClient usage with the same approach. In addition I tried a few test WSDL services and had valid requests and responses there.
Could it be a problem of provided WSDL schema?
Or a problem of my server configuration? I use PHP 5.6.3, php_soap extension is enabled.
Hope you guys can help me. Any your thoughts would be really appreciated.
Thank you.
The code example I found has a different URL...
http://bws.neteven.com/NWS/2 vs http://ws.neteven.com/NWS
$client = new SoapClient("http://ws.neteven.com/NWS", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
Also, you can call methods like this without using __soapCall (even though it would be doing the same thing).
$result = $client->echo(array("EchoInput" => "ReturnMe"));
var_dump($result->EchoOutput);
$result = $client->TestConnection();
var_dump($result->TestConnectionResult);

HORDE Imap PHP client - how to fetch messages

Okay, had no luck with the ZETA email client, so now I tried installing the Horde IMAP Client library. I've managed to login to my account, and make a search for e-mails, also got back the results, but I don't know how to fetch the email data, and the documentation is not really helping:|
I presume that I would have to use the Horde_Imap_Client_Base::fetch() method to get some e-mails, which accepts two parameters, a mailbox name, and a Horde_Imap_Client_Fetch_Query object, but I don't know how to get this second object:|
Should this object be returned by one of the Base functions, or should I build this object with the query parameters I want? If the second, how should I rebuild my search query in the fetch query object from the below example?
Here's how I am searching my INBOX, for mails from a specific contact on a specific day:
$client = new Horde_Imap_Client_Socket(array(
'username' => 'my.email#address.com',
'password' => 'xxxxxxxxxx',
'hostspec' => 'my.mail.server',
'port' => '143',
'debug' => '/tmp/foo',
));
$query = new Horde_Imap_Client_Fetch_Query();
$query->dateSearch(new Date(), Horde_Imap_Client_Search_Query::DATE_ON);
$query->headerText("from","mycontact#contact.email");
$results = $client->search('INBOX', $query);
The Horde_Imap_Client_Base::search() returns an array, which contains the search results(the message id's of the searched emails), and some additional data.
Not completely answering your questions. This is how I search for messages which are not deleted.
$client = new Horde_Imap_Client_Socket(array(
'username' => $user,
'password' => $pass,
'hostspec' => $server,
'secure' => 'ssl'
));
$query = new Horde_Imap_Client_Search_Query();
$query->flag(Horde_Imap_Client::FLAG_DELETED, false);
$results = $client->search('INBOX', $query);
foreach($results['match'] as $match) {
$muid = new Horde_Imap_Client_Ids($match);
$fetchQuery = new Horde_Imap_Client_Fetch_Query();
$fetchQuery->imapDate();
$list = $client->fetch('INBOX', $fetchQuery, array(
'ids' => $muid
));
var_dump($list);
}
$results = $client->search($mailbox, $searchquery, array('sort' => array($sSortDir, $sSort)));
$uids = $results['match'];
for ($i = $i_start; $i < $i_to; $i++)
{
$muid = new Horde_Imap_Client_Ids($uids->ids[$i]);
$list = $client->fetch($mailbox, $query, array(
'ids' => $muid
));
$flags = $list->first()->getFlags();
$part = $list->first()->getStructure();
$map = $part->ContentTypeMap();
$envelope = $list->first()->getEnvelope();
}

Using SoapClient in php in mule

I am using the following php script in mule. When i am running this php file individually(through wamp) i am able to get the required output.
<?php
$client1=new SoapClient('example/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120));
$username = '******';
$password = '******';
//retreive session id from login
$session = $client1->login(
array(
'username' => $username,
'apiKey' => $password,
)
);
$result= $client1->catalogProductInfo(
array(
'sessionId' => $session->result,
'productId' => 1,
)
);
print_r($result);
return $result;
?>
But i want to run the following script through mule. So when i am running it through mule i am getting the following error.
Root Exception stack trace:
com.caucho.quercus.QuercusErrorException: eval::5: Fatal Error: 'SoapClient' is an unknown class name.
at com.caucho.quercus.env.Env.error(Env.java:4480)
at com.caucho.quercus.env.Env.error(Env.java:4399)
at com.caucho.quercus.env.Env.createErrorException(Env.java:4130)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
It says SoapClient is an unknown class. What is the problem here?
Do i have to include some SoapClient here? If so where can i find it. Please help!!
I'm not sure if mule supports php extensions, but that's what it seems by the error. You could try downloading nusoap into your project,
which doesn't require any php extension. The syntaxis is a little bit different though, but shouldn't be harder to adapt your code.
For what it's worth, this is a simple example of a soap request using nusoap (taken from here http://www.richardkmiller.com/files/msnsearch_nusoap.html):
require_once('nusoap/lib/nusoap.php');
$request = array('Request' => array(
'AppID' => 'MSN_SEARCH_API_KEY',
'Query' => 'Seinfeld',
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict',
'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => 0,
'Count' => 50,
'ResultFields' => 'All'))));
$soapClient = new soapclient("http://soap.search.msn.com/webservices.asmx?wsdl", false);
$result = $soapClient->call("Search", $request);
print_r($result);
I hope it helps.
I understand there seems to be a problem with running the soap client inside quercus (rather than Mule).
However instead of focusing on it I would suggest to take a look to the CXF client and the Web services consumer. You are running inside of Mule a powerful opensource ESB, there is no need to write a php script to consume a service, you have all that functinality already present.

Categories