CakePHP 3 Soap Server Error - php

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

Related

Posting xml to SOAP service

I'm fairly new to SOAP and PHP and I'm having some troubles, that I hope someone here on Stack Overflow can help me with.
I'm trying to use this code to post a xml file (retursvar.xml).
I'm using this code to post the file:
<?php
$url = "https://someserver/somefunction";
$options = array(
'login' => 'someusername',
'password' => 'somepassword',
'trace' => 1
);
$client = new SoapClient($url.'?wsdl', $options);
$document = file_get_contents('retursvar.xml');
$params = array('SubmitDocument' => $document);
$response = $client->__soapCall('submitDocument', $params);
but I get this error in the Apache error log:
PHP Fatal error: Uncaught SoapFault exception: [bpws:forcedTermination] business exception in /var/www/html/soaptest.php:15\nStack trace:\n#0 /var/www/html/soaptest.php(15): SoapClient->__soapCall('submitDocument', Array)\n#1 {main}\n thrown in /var/www/html/soaptest.php on line 15
If i call:
var_dump($client->__getFunctions());
immediately after:
$client = new SoapClient($url.'?wsdl', $options);
I get this output:
array(1) { [0]=> string(62) "SubmitDocumentResponse submitDocument(SubmitDocument $payload)" }
What am I doing wrong?
It says that you haven't caught an exception. Try wrapping your code inside try catch block.

How to add new account, update and delete in bing ads under any user account by php?

I have tried below code for updating but it did not work it showed error code:
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] Cannot create an abstract class. in D:\xampp\htdocs\bingTest\UpdateAccount.php:81 Stack trace: #0 D:\xampp\htdocs\bingTest\UpdateAccount.php(81): SoapClient->__call('UpdateAccount', Array) #1 D:\xampp\htdocs\bingTest\UpdateAccount.php(81): SoapClient->UpdateAccount(Object(BingAds\CustomerManagement\UpdateAccountRequest)) #2 D:\xampp\htdocs\bingTest\UpdateAccount.php(62): UpdateAccount(Object(BingAds\Proxy\ClientProxy), Object(BingAds\CustomerManagement\AdvertiserAccount)) #3 {main} thrown in D:\xampp\htdocs\bingTest\UpdateAccount.php on line 81
$wsdl = "https://clientcenter.api.sandbox.bingads.microsoft.com/Api/CustomerManagement/v9/CustomerManagementService.svc?singleWsdl";
$proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, $UserName, $Password, $DeveloperToken, $AccountId, null, null);
$last_modified_time=GetAccount($proxy,$AccountId);
$account_obj=new AdvertiserAccount();
$account_obj->AccountType='Advertisement';
$account_obj->CountryCode="US";
$account_obj->CurrencyType="USD";
$account_obj->Id=$AccountId;
$account_obj->LastModifiedTime=$last_modified_time;
$account_obj->Name="Test Account";
$account_obj->AccountLifeCycleStatus='Pause';
UpdateAccount($proxy, $account_obj);
function GetAccount($proxy,$AccountId)
{
$account_obj=new GetAccountRequest();
$account_obj->AccountId=$AccountId;
return $proxy->GetService()->GetAccount($account_obj)->Account->LastModifiedTime;
}
function UpdateAccount($proxy, $update_account_info)
{
$request = new UpdateAccountRequest();
$request->Account = $update_account_info;
return $proxy->GetService()->UpdateAccount($request);
}
In case if you still need a solution. You need to do this:
$encodedAccount = new \SoapVar(
$account,
SOAP_ENC_OBJECT,
'AdvertiserAccount',
'https://bingads.microsoft.com/Customer/v9/Entities'
);
$request->Account = $encodedAccount;

Zend 2 Error : Uncaught exception 'Zend\Stdlib\Exception\InvalidArgumentException'

I retrieve data from Zend 2 session container on layout via bootstarp method.
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$sm = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$user = $this->getUser($sm);
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->user = ($user) ? $user: false;
}
public function getUser($sm)
{
$user= false;
$userTable= $sm->get('User\Model\UserTable');
$userSession = new Container('userSession');
//RETRIEVE USER FROM DB
return $user;
}
Now i'm getting following error sometimes (not always)
Fatal error: Uncaught exception 'Zend\Stdlib\Exception\InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php:184 Stack trace: #0
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php(411): Zend\Stdlib\ArrayObject->exchangeArray(NULL) #1 [internal function]: Zend\Stdlib\ArrayObject->unserialize('a:4:{s:7:"stora...') #2
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start() #3
/var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\Session\SessionManager->start() #4
/var/www/T2oRecruitment/app/module/Application/Module.php(22): Zend\Session\AbstractContainer->__construct('userSession') #5
/var/www/T2oRecruitment/app/module/Application/Module.php(43): Application\Module->getUser(Object(Zend\S in /var/www/T2oRecruitment/app/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 184
What is the issue ?
Please try with this:
In Module.php file --->
use Zend\Session\Config\SessionConfig, Zend\Session\SessionManager,
Zend\Session\Container, Zend\Mvc\MvcEvent;
// other libraries
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$sm = $e->getApplication()->getServiceManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$config = $sm->get('Config');
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config['session']);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
$user = $this->userSession($sm);
$viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
$viewModel->user = ($user) ? $user: false;
}
In module.config.php file --->
return array(
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true
),
);
Hope, this will give some idea to you, for fixing your issue. Thanks :)
There is official bug https://github.com/zendframework/zf2/issues/4821
it's still open, but you can check the progress...

PHP SoapClient to call a soap method with authentication

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

Zend soap call for method with hyphen

I rewrite soap client file using Zend framework.
This is old method. it is working.
function getBassaService(){
global $service;
$h="127.0.0.1";
$p="8000";
if($service==null){
$service = new SoapClient("/test/php/bassa.wsdl", array(
"soap_version" => SOAP_1_2,
"trace" => 1,
"exceptions" => 1,
"location" => "http://".$h.":".$p));
}
return $service;
}
function getAllDownloads(){
global $service;
$client = getService();
try{
$results = $client->__soapCall("list-all", array());
}catch(SoapFault $e){
print($e->faultstring);
}
return $result;
}
This is my new code. I use Zend_Soap_Client.
const HOST = "127.0.0.1";
const PORT = "8095";
protected $_client;
public function __construct()
{
$this->_client = new Zend_Soap_Client(APPLICATION_PATH ."/services/bassa.wsdl",
array(
"soap_version" => SOAP_1_2,
"uri" => "http://". self::HOST .":". self::PORT
)
);
}
public function getAllDownloads()
{
$result = $this->_client->list-all();
return $result;
}
My soap server has list-all method. I want soap call to that method. But following error has occurred. Because method name has hyphen.
Notice: Undefined property: Zend_Soap_Client::$list in /home/dinuka/workspace/testzend/application/services/SoapClient.php on line 57
Fatal error: Call to undefined function all() in /home/dinuka/workspace/testzend/application/services/SoapClient.php on line 57
How i fixed it. Please help me.
strange. that's should work. it might be a a bug in ZF framework. maybe it's trying to convert the function name into a camel case function name with variables.
Try to use the magic function directly by calling:
$this->_client->__call('list-all', array('param1' => $param1))

Categories