SAP and php SOAP COMMIT - php

I have created a Webservice from a BAPI in SAP to insert some AccountDocuments into SAP. The system in these cases needs a COMMIT-call after a successful insert call. Both of these functions must be called in "one context".
Now I'm facing the problem that I don't know how to do this in php or if there is any way to do this?
I have created the following example, but it doesn't work. The COMMIT function gets executed but it has no impact in SAP. I cannot see the data in the databases, although the first call returns "Data successfully booked". I know that you must confirm this with the COMMIT call in SAP. In SE37 there is a way to put 2 function calls into one Sequence. I'm searching the php-way to do this.
function insertAccntDoc($accntgl, $currAmount, $docHeader, $accntTax)
{
#Define Authentication
$SOAP_AUTH = array( 'login' => SAPUSER,
'password' => SAPPASSWORD);
$WSDL = "url_to_my_wsdl";
#Create Client Object, download and parse WSDL
$client = new SoapClient($WSDL, $SOAP_AUTH);
#Setup input parameters (SAP Likes to Capitalise the parameter names)
$params = array(
'AccountGl' => $accntgl,
'CurrencyAmount' => $currAmount,
'DocumentHeader' => $docHeader,
'AccountTax' => $accntTax
);
#Call Operation (Function). Catch and display any errors
try
{
$result = $client->AcctngDocumentPost($params);
$result = $client->BapiServiceTransactionCommit();
$result->Gebucht = 'Committed';
if(count($result->Return) > 1)
{
$client->BapiServiceTransactionRollback();
$result->Gebucht = 'Rollback';
}
else if($result->Return->item->Type == 'S')
{
try
{
$client->BapiServiceTransactionCommit();
$result->Gebucht = 'Committed';
}
catch(SoapFault $exception)
{
$client->BapiServiceTransactionRollback();
$result->Fehler = "***Caught Exception***<br>".$exception."<br>***END Exception***<br>";
$result->Gebucht = 'Fehler beim Committen';
}
}
}
catch (SoapFault $exception)
{
$client->BapiServiceTransactionRollback();
$result->Fehler = "***Caught Exception***<br>".$exception."<br>***END Exception***<br>";
$result->Gebucht = 'Fehler beim Anlegen';
}
#Output the results
$result->FlexRet = 'insertAccntDoc';
return $result;
}
Thanks!

This link gives details on how to use "stateful" web services. This is required to have a shared session.
http://scn.sap.com/thread/140909

Related

AWS SDK EC2 - "DescribeInstances" Exception, skip instance in list

I have a list of Instances ID saved in DB.
a periodic check validates those ID's against AWS.
The problem is that if one of the instances doesnt exist then i get Exception and the whole request fails (none of the ID's return).
Is there a way to skip that missing ID and get back all data except for that specific instanceID?
My code:
$requesltArray = ['Filters' => $this->_Filters, 'InstanceIds' => $this->_InstanceIDs];
try {
$reservations = $this->_EC2Client->DescribeInstances($requesltArray)->toArray();
} catch (Ec2Exception $exc) {
echo $exc;
return [];
}
results in Exception:
aws sdk Error executing "DescribeInstances" InvalidInstanceID.NotFound
Depending of the number of instances you have, you might consider then to perform your DescribeInstances request for each individual IDs.
$reservations = [];
foreach($this->_InstanceIDs as $anInstance){
try {
$requesltArray = ['Filters' => $this->_Filters, 'InstanceIds' => $anInstance];
$aReservation = $this->_EC2Client->DescribeInstances($requesltArray)->toArray();
$reservations[] = $aReservation;
} catch (Ec2Exception $exc) {
// --> Delete the instance from your database?
continue;
}
}
dd($reservations);

Does Laravel 5.3019 database Transaction method work?

I've use Larvel 5.0 with Database transaction all the method in my previous web application it work as well and we are really love it because this application help me much more than our estimated
so we have create another webs application by using this newest version of this framework and used the same Database structure but finaly it would not work for me and another one to.
I have as more peoples and post on some toturial website for asking any belp but not yet get any solution so I record this video for sure about this case.
Issue: My issue I've disabled (//commit()) method all data still can insert into Database.
final function Add()
{
if ($this->request->isMethod('post')) {
//No you will see this method use with Try Catch and testing again
//DB::beginTransaction(); // Ihave testing with outside of try and inside again
Try{
DB::beginTransaction();
$cats = new Cat();
$catD = new CategoryDescriptions();
$cats->parent_id = $this->request->input('category_id');
$cats->status = ($this->request->input('status')) ? $this->request->input('status') : 0;
if (($res['result'] = $cats->save())== true) {
$catD->category_id = $cats->id;
$catD->language_id = 1;
$catD->name = $this->request->input('en_name');
if (($res['result'] = $catD->save()) === true) {
$catD2 = new CategoryDescriptions();
$catD2->category_id = $cats->id;
$catD2->language_id = 2;
$catD2->name = $this->request->input('kh_name');
$res['result'] = $catD2->save();
}
}
if(!empty($res)) {
//DB::commit();
}
return [$res,($res['result'] = $catD->save())];
}catch(\Exception $e){ // I have already try to use Exception $e without backslash
DB::rollback();
}
}
$cat = Cat::with(['CategoryDescriptions', 'children'])->where('status', 1)->get();
return view('admin.categories.add', ['cat' => $cat]);
}
You can check on my video to see that .
Check on my video
I don't know why your code did not work. But you can try with this code I think it's will work. Laravel transaction documentation
try{
DB::transaction(function)use(/*your variables*/){
// your code
});
}catch(\PDOException $exception){
//debug
}
If any exception occurs it will automatically rollback. If you want manual rollback then inside transaction you can throw a manual exception based on your logic.

how to call a soap webservice with struct input parameters?

I want to interact with SOAP (as a client) and am not able to get the right syntax for input parameters. I have a WSDL URL that I have tested it with SoapUI and it returns result properly. There are two functions defined in the WSDL, but I only need one ("FirstFunction" below). Here is the script I run to get information on the available functions and types:
$client = new SoapClient("http://example.com/webservices?wsdl");
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
And here is the output it generates:
array(
[0] => "FirstFunction Function1(FirstFunction $parameters)",
[1] => "SecondFunction Function2(SecondFunction $parameters)",
);
struct Amount {
anyURI Identifier;
Information charge;
string referenceCode;
}
struct Information {
string description;
decimal amount;
string code;
}
According to above result I developed my client with nusoap and php as below:
class Information
{
public $description;
public $amount;
public $code;
}
class Amount {
public $Identifier;
public $charge;
public $referenceCode;
}
$charge = new Information();
$charge->description = "ROUTE=XXX|abc=".$code;
$charge->amount = "NULL";
$charge->code = $chargecode;
$params = new Amount();
$params->Identifier =$num;
$params->charge = $charge;
$params->referenceCode = $refcode;
$header = new SoapHeader('key', $key);
$client->__setSoapHeaders($header);
try
{
$res = $client->__call('charge',array('parametrs'=>$params));
print_r($res->return);
}
catch(PDOException $e)
{
print_r($e->getMessage());
}
I get the following error as result:
Uncaught SoapFault exception: [soapenv:Server] unknown
In my opinion the best way to achieve it is to use a WSDL to php generator such as the PackageGenerator project. It abstracts the whole process so you only deal with objects without really worrying about SOAP.

WSO2AS Soapcall of service returns null

I'm developing a web-app, which needs data from a database.
For the communication with the db I use WSO2AS.
I made a database and linked that to the data service created, when i test the service in the admin panel of WSO2, I get the data needed from the database.
The data service I created is called TestService.
Now I want to have the same response in my php template as well, using this code.
<?php
try {
$client = new SoapClient('http://192.168.178.12:9763/services/TestService?wsdl');
$result = $client->__soapCall('greet');
printf("Result = %s\r\n", $result->return);
} catch (Exception $e) {
printf("Message = %s\r\n",$e->__toString());
}
?>
But this gives NULL, when I try to dump the $result.
When I try to execute an example WSO2 created, I do get the right result. While the soapcall code is the same, only the service name is different.
<?php
try {
$client = new SoapClient('http://192.168.178.12:9763/services/HelloService?wsdl');
$result = $client->__soapCall('greet', array(array('name' => 'Sam')));
printf("Result = %s\r\n", $result->return);
} catch (Exception $e) {
printf("Message = %s\r\n",$e->__toString());
}
?>
This code returns "Hello Sam !!!".
So I wonder what I did wrong, I personally think I made a mistake in implementing the service itself, but can't find it.
If any more information is needed feel free to ask, hope someone can help me with this.
Thanks in advance!
Apparently you need to have arguments in your soapcall.
After calling this __soapCall('greet', array());
It gave the proper response.

Redirecting when encountering an Ecircle SOAP API Error

I'm experimenting with Ecircle soap api, currently i'm using it to send message to new users who sign up on my site. I'm trying to do an error handling so that when the API fails, the function will send me an email with the error and the user id/email and then return to the main function and continue on it's merry way. That way I'll be aware of the problem and the user will be able to continue what they're doing without any interference. Here's an example of a function :
function lookupuserbyemail($userinput) {
$ns = "http://webservices.ecircleag.com/rpcns";
$client = new soapclient('http://webservices.ecircle-ag.com/soap/ecm.wsdl');
$logonparams = array('realm' => "http://email.mywebsite.com",
'user' => "admin#hotmail.com",
'passwd' => "12345");
// check if logon was successful
$result = $client->logon($logonparams);
if (is_soap_fault($result)) {
sendMsgToMe();
return;
}
$sessionid = $result->logonReturn;
// logon ok, now call the function
$params = array('email' => $userinput,
'session' => $sessionid);
$result = $client->lookupUserByEmail($params);
//check if the function was executed properly
if (is_soap_fault($result)) {
$result = "error";
return $result;
}
// print the result
$userinfo = htmlspecialchars($result->lookupUserByEmailReturn);
// now logout
$params = array('session' => $sessionid);
$client->logout($params);
if (is_soap_fault($result)) {
$result = "error";
return $result;
}
return $userinfo;
}
According to their wiki at http://developer.ecircle-ag.com/apiwiki/wiki/SynchronousSoapAPI#section-SynchronousSoapAPI-PHPSample, the code below is to detect an error or when an API function fails:
$result = $client->logon($logonparams);
if (is_soap_fault($result)) {
sendMsgToMe();
return;
}
That is not the case however, instead of reporting the error, it just crashes and the user would see this :
Uncaught SoapFault exception: [soapenv:Server.userException] com.ecircleag.webservices.EcMException: Error: blablablabla.
Evidently this is not so great since the user will be unable to continue if the ecircle service is down, therefore i would like to know if it's possible for the my code to continue running even when a SOAP error is logged.
Thank you :)

Categories