I am trying to access a webservice (JAX-WS) with wsdl using php (5.3.5). Following is the code I am using :
class insoapauth
{
public $Username;
public $Password;
public function __construct($username, $pass)
{
$this->Username = $username;
$this->Password = $pass;
}
}
$client = new SoapClient("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin?wsdl", array( "login" => "SOAPDW", "password" => "DW#2012"));
// Create the header
$auth = new insoapauth("SOAPDW", "DW#2012");
$header = new SoapHeader("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin", "APICredentials", $auth, false);
try {
$result = $client->__soapCall("getDataWS", array(
"CrmSearchInformation" => array(
"searchKeyValue" => "93700801021"
)
));
echo("<br/>Returning value of __soapCall() call: ".$result);
}catch(SoapFault $exception)
{
print_r("Got issue:<br/>") ;
var_dump($exception);
}
Alternatively I tried another way using the SoapHeader and supplying it while the method call. But I am always getting the SoapFault exception :
Could not connect to host
More details exception:
SoapFault exception: [HTTP] Could not connect to host in
C:\wamp\www\SOAPTest\client\insoaptest.php:103 Stack trace: #0
[internal function]: SoapClient->_doRequest('_soapCall('getDataWS',
Array) #2 {main}
However, using soapUI I can connect to the soapsever and can call the soapmethod with the same credentials.
Following is some example code to access the WS - I guess it's in Java- that comes with the manual:
INBeanService service = new INBeanService();
CXINWS wsPort = service.getCXINWSPort();
String username = "crmtestuser";
String password = "crmpassword";
BindingProvider bp = (BindingProvider) wsPort;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
try {
CrmSearchInformation crmSearchInfo = new CrmSearchInformation();
crmSearchInfo.setSearchKeyValue(msisdn);
CrmSearchResult result = wsPort.getDataWS(crmSearchInfo);
//handle result
System.out.println("Result state: " + result.getSearchResultState());
} catch (NxWsException e) {
// handle exceptions
}
Can anybody please show me some light how I can access a wsdl webservice from php with authentication ?
I have had this error before because of a cached WSDL ... try disabling the cache :
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
Docs on these settings here
Related
I need to create a PHP SOAP client based on this specification:
https://exdev.server.propctrl.com/v5.4/Basic/AgencyIntegration.svc?wsdl
I am able to create my soap client, and when I try to call a function it returns saying access denied:
Message: Access is denied.
Based on documentation, there is no verification/auth method that I first need to call, but it seems I have to use a type called Credentials.
struct Credentials { string Password; string Username; }
I then tried created a Credentials object:
class Credentials {
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
}
And assigned new values to it and used it in my SoapHeaders:
$credentials = new Credentials($username, $password);
$header = new SoapHeader('http://localhost','Credentials',$credentials,false);
$client->__setSoapHeaders($header);
When I then use a function I still get the same error:
echo "<pre>";
try {
$response = $client->__soapCall("EchoAuthenticated", array("EchoAuthenticated" => "asdfasdf"));
var_dump($response);
}
//catch exception
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
Message: Access is denied.
I guess my question is that I don't know where/how to pass through the credentials in order for the API to authorise my request.
Any ideas/suggestions?
update1:
The authentication method should be explained in some documentation, anyway there are Soap services that use HTTP Header for authentication, for example
$soapClient->setHttpHeaders([
'clientId' => $username,
'clientSecret' => $password
]);
But please consider that keys ( in my example clientId and clientSecret ) depend by the service implementation.
Do you have a service documentation?
I try to create a Soap Server in CakePHP 3 but if I want to connent with my client i become error's every time.
I set up the server in a function:
public function view($id) {
$connection = ConnectionManager::get('default');
$user = $connection->execute('SELECT * FROM users WHERE id='.'"'.$id.'"')->fetchAll('assoc');
$obj = new Post;
$this->viewBuilder()->layout = false;
$this->autoRender = false;
ini_set("soap.wsdl_cache_enabled",0); //disable wsdl cache
$server = new SoapServer(null, array(
'uri' => 'http://localhost/test-uri',
'encoding'=>'UTF-8'
)
);
$server->setObject($obj);
$server->handle();
}
in a model I create this function:
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\Utility\Xml;
class Post {
function testfunktion($param){
return $param;
}
}
my client script show this:
$soap = new SoapClient(
null,
array(
"location" => "http://localhost/shop_system/users/view/2",
"uri" => "http://test-uri",
"trace" => 1
)
);
try {
$product = $soap->testfunktion("Michael");
} catch (SoapFault $e) {
echo $e;
print($soap->__getLastResponse());
}
and this is my output:
SoapFault exception: [Client] looks like we got no XML document in C:\xampp\htdocs\shop_system\webroot\client.php:15 Stack trace: #0 C:\xampp\htdocs\shop_system\webroot\client.php(15): SoapClient->__call('testfunktion', Array) #1 C:\xampp\htdocs\shop_system\webroot\client.php(15): SoapClient->testfunktion('Michael') #2 {main}
Notice (8): Undefined index: HTTP_ACCEPT_LANGUAGE [APP/Controller\UsersController.php, line 22]Michael
i dont know what i must do by this error
I make soap requests using this Code :
try {
$S = new \SoapClient($this->wsdl);
$method = 'method';
$params = array('ID' => $Id, 'Code'=> $Code);
return $S->__call($method, $params);
}catch (\Exception $e) {
return $e->getMessage();
}
But an Exception is raised :
SoapFault exception: [HTTP] Could not connect to host
I tried to return all functions described in the WSDL for the Web service
$S = new \SoapClient($this->wsdl);
return $S->__getFunctions();
And I have all functions including my 'method' used above.
What could be the problem?
Getting this error while using soap service php :
Fatal error: Uncaught SoapFault exception: [Client] Function ("getProxy") is not a valid method for this service in C:\webserver\www\feeder\index.php:7 Stack trace: #0 C:\webserver\www\feeder\index.php(7): SoapClient->__call('getProxy', Array) #1 C:\webserver\www\feeder\index.php(7): SoapClient->getProxy() #2 {main} thrown in C:\webserver\www\feeder\index.php on line 7
here's my code :
<?php
$wsdl = "http://localhost:8182/fg/live.php?wsdl";
$username = "aaaaa";
$password = "123456";
$client = new SoapClient($wsdl);
$proxy = $client->getProxy();
$token = $proxy->GetToken($username, $password);
var_dump("Get Token = ".$token);
$table = $proxy->ListTable($token);
var_dump("Tabel = ".$table);
?>
There's something wrong with my code ?
Please have a look at the PHP SoapClient Doku, there is no getProxy-Method. The client itself calls the functions defined in wsdl:
$token = $client->GetToken();
$client->ListTable($token);
And make shure, that you check $token, if it's really a single variable, or if it is an object.
There is a wcf server and I am trying to connect it and send requests.
The code is :
$url = "http://serverip:8080/example.svc?wsdl";
$params = array(
'Username' => 'username',
'Password' => 'password'
);
$client = new SoapClient($url);
var_dump($client->__getTypes()); //it works
$result = $client->Login($params); //gives error
But everytime I am getting internal server error. I spend 5 days and searhed all the web and tried all different methods but I am always getting internal server error. Error is below :
protected 'message' => string 'The server was unable to process ...
private 'string' (Exception) => string '' (length=0) ...
If I use SOAP UI I can send and get data or if I call "$client->__getTypes()" from php server, I get types. But if I call implemented functions with PHP it doesn't work. Are there anyone to help me?
Thanks a lot,
Perhaps you should pass the parameters as object as in the following example
try {
$client = new SoapClient('http://serverip:8080/example.svc?wsdl');
$params = new stdClass();
$params->Username = 'Username';
$params->Password = 'Password';
$client->Login($params);
} catch (SoapFault $e) {
// error handling
}