SoapFault: looks like we got no XML document Magento and laravel - php

i am with a problem in my application Laravel, when i use the SoapClient, for example my_object_soap->login(); returned this error:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML
I already tried several solutions that I researched in google and here, but I did not solve my problem.
my code follows:
ini_set("soap.wsdl_cache_enabled",0);
ini_set("soap.wsdl_cache",0);
ini_set("error_reporting",-1);
ini_set("display_errors","On");
$wsdl_url = "https://example.com/index.php/api/v2_soap/index/?wsdl";
$apiAuth = new \stdClass();
$apiAuth->username = trim("myusermagento");
$apiAuth->apiKey = trim("mykeymagento");
try{
$proxy = new SoapClient($wsdl_url,array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true));
$session = $proxy->login($apiAuth);
$data = $session;
$status = true;
$responseStatus = 200;
} catch(SoapFault $e) {
$error = $e->getMessage();
$data = $proxy->__getLastResponse();
$status = false;
$responseStatus = 500;
}
return Response::json([
'success' => $status,
'data' => $data,
'erros'=> $error,
],$responseStatus);
I have no idea which a problem, when i tested in SoapUI, with this user and key, it's alright, but in my app not.
My magento version app is 1.6.2, and my php is 7.2, I already tried to downgrade to php 5.6 because it could be incompatibility with the magento version and my php but it still did not work.
Can someone help me?

Try this one, structure your request as follows
$options = array('trace'=> true,'exceptions' => true);
$client = new \SoapClient('https://www.example.com?wsdl',$options);
$params = new \stdClass();
$params->key1 = 'XXXXXX';
$params->Key2 = 'XXXXX';
$soapVar = new \SoapVar($params,SOAP_ENC_OBJECT);
$header = new \SoapHeader('https://www.example?wsdl','credentials',$soapVar);
$client->__setSoapHeaders(array($header));
$result=$client->login(function parameters here);
Cheers!!!

Related

php soap client issue

I have to develop a php client which connects to a soap webservice server.
With SoapUI, I can test the webservice which is working fine.
But from my php client, I get the following error:
syntax error near << from >>
Here is my php client code:
$wsdl = 'http://intrageo.cannes.fr:81/AdresseRecherche/searchByWhereClause?wsdl';
$trace = true;
$exceptions = false;
$xml_array['context'] = '?';
$xml_array['table'] = 'adr_digadr';
$xml_array['colonneARecuperer'] = 'numero';
$xml_array['clauseWere'] = 'nomvoie= \'BOULEVARD COINTET\'';
$xml_array['nbMaxLignes'] = 10;
try {
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->getDistinctValue($xml_array);
} catch (Exception $e) {
echo "Error!";
echo $e->getMessage();
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
Thanks for help.
It works if I use $response=$client->_soapCall("getDistinctValue",$xml_array); instead of $response=$client->getDistinctValue($xml_array)

How to connect to an Office365 Server using PHP-EWS (Getting a 404)

I'm currently attempting to update an internal tool to handle an upgrade of our exchange servers to office 365.
I'm using the most recent version of James Armas's PHP-EWS tool. jamesiarmes/php-ews
Here is the code snippet that is inside of a function that we use to get events for a certain date range.
$email = '*email#domain*';
$password = '*password*';
$server = 'outlook.office365.com';
// Define EWS
//$ews = EWSAutodiscover::getEWS($email, $password);
$ews = new Client($server, $email, $password);
// Set init class
$request = new FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date;// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $end_date;// an ISO8601 date later than the above
// Only look in the "calendars folder"
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $email_address;
// Send request
$response = $ews->FindItem($request);
When this code is run, we get a 404 from the SOAP client:
Fatal error: Uncaught exception 'Exception' with message 'SOAP client returned status of 404.' in /*dirs*/Client.php:1650 Stack trace: #0 /*dirs*/Client.php(1633): jamesiarmes\PhpEws\Client->processResponse(NULL) #1 /*dirs*/Client.php(670): jamesiarmes\PhpEws\Client->makeRequest('FindItem', Object(jamesiarmes\PhpEws\Request\FindItemType)) #2 /*dirs*/index_dev.php(64): jamesiarmes\PhpEws\Client->FindItem(Object(jamesiarmes\PhpEws\Request\FindItemType)) #3 /*dirs*/index_dev.php(269): getEventHTML('email#domain...', '2017-07-18T02:0...', '2017-07-18T21:5...') #4 {main} thrown in /*dirs*/Client.php on line 1650
I believe that I do have the connection set up correctly, because when I alter the credentials, I do get a 401.
I have looked into this page: PHP-EWS “Soap client returned status of 404”
And I've tried the outlook.office365.com/EWS/Exchange.asmx endpoint as well, but I still get the SOAP 404.
Because of this, I thought this was enough of a separate question. (Although the more I research, the more that the REST client may be the next step)
I might be on the completely wrong track as well, so any help would be greatly appreciated!
I had a similar issue when we moved from an on-premises Exchange server to Office 365 and managed to trace the issue back to SoapClient.php under php-ntlm.
Going from the error that was thrown in your request:
Fatal error: Uncaught exception 'Exception' with message 'SOAP client returned status of 404.' .... thrown in /*dirs*/Client.php on line 1650
If we look at that line in Client.php the exception appears to come from the function that calls the aforementioned SoapClient.php script.
protected function processResponse($response)
{
// If the soap call failed then we need to throw an exception.
$code = $this->soap->getResponseCode();
if ($code != 200) {
throw new \Exception(
"SOAP client returned status of $code.",
$code
);
}
return $response;
}
I was able to resolve the issue by modifying the CURL request options in SoapClient.php (located around line 180).
Original Code:
protected function curlOptions($action, $request)
{
$options = $this->options['curlopts'] + array(
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $this->buildHeaders($action),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM,
CURLOPT_USERPWD => $this->options['user'] . ':'
. $this->options['password'],
);
// We shouldn't allow these options to be overridden.
$options[CURLOPT_HEADER] = true;
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $request;
return $options;
}
Modified Code:
protected function curlOptions($action, $request)
{
$cOpts = array(
CURLOPT_PROXY => "my.proxy.com:8080",
CURLOPT_PROXYUSERPWD => $this->options['user'] . ':'
. $this->options['password'],
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $this->buildHeaders($action),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_NTLM,
CURLOPT_USERPWD => $this->options['user'] . ':'
. $this->options['password'],
);
$options = $this->options['curlopts'] + $cOpts;
// We shouldn't allow these options to be overridden.
$options[CURLOPT_HEADER] = true;
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = $request;
return $options;
}
I set CURLOPT_SSL_VERIFYPEER to false and also added proxy options to the request as the connection is made from inside a corporate network which requires proxy authentication to access any external sites.
In my mailing PHP script I create the client using the following code:
$server = 'outlook.office365.com';
$username = 'user#domain.com';
$password = 'myPassword';
$version = Client::VERSION_2016;
$client = new Client($server, $username, $password, $version);
Have you tried using the solution from https://github.com/jamesiarmes/php-ews/issues/196 eg change
$version = Client::VERSION_2016;
$ews = new Client($server, $email, $password,$version);
I can't make out what is wrong with your code but maybe the following helps. I'm using this script successfully to export my calendar regulary from o365.
Host and User are like this:
host = "outlook.office365.com"
username = "user#domain.com"
Script:
$start_date = new Datetime('today -1 months');
$end_date = new Datetime('today +1 months');
$timezone = 'W. Europe Standard Time';
$ini_array = parse_ini_file($credentials_ini);
$host = $ini_array['host'];
$username = $ini_array['username'];
$password = $ini_array['password'];
$version = Client::VERSION_2016;
$client = new Client($host, $username, $password, $version);
$client->setTimezone($timezone);
$request = new FindItemType();
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = $start_date->format('c');
$request->CalendarView->EndDate = $end_date->format('c');
$request->ConnectionTimeout = 60;
$response = $client->FindItem($request);
$response_messages = $response->ResponseMessages->FindItemResponseMessage;
foreach ($response_messages as $response_message) {
$items = $response_message->RootFolder->Items->CalendarItem;
foreach ($items as $event){
$id = $event->ItemId->Id;
$subject = $event->Subject;
$location = $event->Location;
// ...
// do something with it
}
}

Getting could not connect to host error when using soap

I am using SOAP to call a web servicefrom a Linux Centos 6 server and a php client. In this week I have been getting could not connect to host error from soapCall method. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time. I have read most answers to related questions here but my problem have not been solved.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I changed SOAP from _1_1 to _1_2 but nothing changed.
This is how I call SOAP webservice, please note Service?wsdl should be Service.wsdl
Example
//Initialize values
$wsdl = "Service.wsdl";
$url = "http://x.x.x.x:x/gw/services/";
$username = "********"; //add username
$password = "********"; //add password
$client = new SoapClient("$url".$wsdl);
$params = array(
"username"=>$username,
"password"=>$password
);
$response = $client->UserLogIn($params); //UserLogIn is the function name
var_dump($response); // to see webservice response

Softlayer API PHP error Function ("setObjectFilter") is not a valid method for this service

I tried to use object filter to get valid device:
Below is the php code:
$client= SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
$filter = new stdClass();
$filter->applicationDeliveryControllers = new stdClass();
$filter->applicationDeliveryControllers->billingItem = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = $bId;
$client->setObjectFilter($filter);
try {
$mask ='mask[id, name]';
$client->setObjectMask($mask);
$myInstance = $clientNetscaler->getApplicationDeliveryControllers();
} catch(exception $ex) {
}
I got the following error in my run time environment:
There was an error querying the SoftLayer API: Function
("setObjectFilter") is not a valid method for this service
The error came from line $client->setObjectFilter($filter);
Anybody has any idea of why there's such error?
For me the filter is working fine. Just in case, I copied my code. Please make sure you have PHP 5.2.3 or higher and the PHP extension for SOAP. Also try re-downloading the Softlayer PHP client https://github.com/softlayer/softlayer-api-php-client and try again.
Regards
<?php
require_once ('/SoapClient.class.php');
$apiUsername = 'set me';
$apiKey = 'set me';
$accountService = Softlayer_SoapClient::getClient('SoftLayer_Account', null,$apiUsername, $apiKey);
$bId = 51774239;
$filter = new stdClass();
$filter->applicationDeliveryControllers = new stdClass();
$filter->applicationDeliveryControllers->billingItem = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = $bId;
$accountService->setObjectFilter($filter);
$mask ='mask[id, name]';
$accountService->setObjectMask($mask);
try {
$myInstance = $accountService->getApplicationDeliveryControllers();
print_r($myInstance);
} catch (Exception $e) {
die('Unable to executre the request. ' . $e->getMessage());
}

GoogleAds PHP SoapFault - AdError.CANNOT_SET_FIELD # operations[0].operand.ad.url

I am using the library googleads/googleads-php-lib from github.
I am trying to create a text ad, but I am getting an error that I cannot set the URL field. The code has been working for quite some time but has suddenly stopped due to this error.
The SoapFault exception that is thrown is:
[AdError.CANNOT_SET_FIELD # operations[0].operand.ad.url]
My code is as follows:
require_once('Google/Api/Ads/AdWords/Lib/AdWordsUser.php');
$developerToken = '*removed*';
$clientCustomerId = '*removed*';
$userAgent = 'test';
$settingsIniPath = './vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/settings.ini';
$oAuth = array(
'client_id' => '*removed*',
'client_secret' => '*removed*',
'refresh_token' => '*removed*',
);
$adWordsUser = new AdWordsUser(null, $developerToken, $userAgent, $clientCustomerId, $settingsIniPath, $oAuth);
$adWordsUser->SetDefaultVersion('v201409');
$adGroupId = *removed*;
$textAd = new TextAd();
$textAd->headline = 'headline text';
$textAd->description1 = 'description1 text';
$textAd->description2 = 'description2 text';
$textAd->displayUrl = 'www.example.com';
$textAd->url = 'http://www.example.com/';
$adGroupAd = new AdGroupAd($adGroupId, $textAd);
$operations = array(new AdGroupAdOperation($adGroupAd, null, 'ADD'));
$adGroupAdService = $adWordsUser->GetService('AdGroupAdService');
$result = $adGroupAdService->mutate($operations);
I am not sure what could be causing this error. Any help would be greatly appreciated.
got caught with that too. The problem seems to be that "url" is no longer supported, you have to use "targetUrls" of upgraded URLs API instead:
http://googleadsdeveloper.blogspot.cz/2015/05/reminder-adwords-destination-urls-will.html

Categories