I have a function which handles the SOAP based web service.
When I run the function via URL I am getting XML response. but when I run the function through CRON I am not getting xml response.
<?php
$logFile = 'checking'.date('Y-m-d').'.log';
$client = new SoapClient("http://DOMAIN/services/weburl?wsdl",array( "trace" => true, 'use' => SOAP_LITERAL));
$params = array('username' => 'username', 'Password' => 'password', 'delatdate' => '17/06/2015 18:00:00');
try{
$response = $client>-productOnHand($params);
} catch(SoapFault $e){
echo $e->faultcode; echo '<br />';
echo $e->getMessage(); echo '<br />';
}
require_once 'app/Mage.php';
Mage::app();
Mage::log(print_r($response, true), null, $logFile);
Mage::log(print_r($client->__getLastResponse(), true), null, $logFile);
?>
If I run this web page via URL I am getting valid xml response. But when this page is being called through CRON I am not getting valid response.
I fixed this issue.
Before default_socket_timeout was set as 60. I raised it as 600. Now I could able to receive.
Related
I am using TwitterAPIExchange to publish tweets to Twitter. Over the last 4 months I had no problems until I switched from HTTP to HTTPS.
I did not think this would be a problem as I do not even see this as a setting within the Developers APP and I am doing all this through crontab.
I am using the identical code below on two different servers and the one with SSL I get a successful connection (no errors) but no posting of the tweet -- meanwhile on the server without SSL I get a successful connection and a successful post.
Can a IP get blocked and if so, how do I check it if is, or is SSL a problem -- what do I need to do to fix this?
require_once('TwitterAPIExchange.php');
$connection = array('oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'xxx', 'consumer_key' => 'xxx', 'consumer_secret' => 'xxx');
try {
$twitter = new TwitterAPIExchange($connection);
echo 'Connection success <br /> ';
$response = $twitter->buildOauth('https://api.twitter.com/1.1/statuses/update.json', 'POST')->setPostfields(array('status' => 'Test Tweet'))->performRequest();
$json = json_decode($response, true);
if (!empty($json['id_str'])) echo 'Post success: '.$json['id_str'];
}
catch (Exception $ex) {
echo $ex->getMessage();
}
Added CURLOPT_SSL_VERIFYPEER => false to TwitterAPIExchange
I'm trying to connect to a web service using PHP's soap client which I can successfully do using Visual Studio, pressing F5 and running the page locally which works a treat.
As soon as I upload the exact same file to my apache web host, I keep getting the error: "failed to load external entity".
Here's my code with the credentials and url taken out...
Any ideas?
<?php
header("Access-Control-Allow-Origin: http://example.com");
header("Access-Control-Request-Method: GET,POST");
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
try
{
$soapclient = new SoapClient('http://example.com');
$params = array ('SystemID' => 'testID','Username' => 'test', 'Password' => 'test');
$response = $soapclient->GetEngineerList($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);
}
strings are not read twice and parsed in single quotes
$soapclient = new SoapClient('$url');
try
$soapclient = new SoapClient($url);
also...do you have $url = ''; anywhere?
UPDATE 1
please try using basic auth to get to your wsdl:
$login = 'bert';
$password = 'berts password';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#www.server.com/path/to/wsdl',
array(
'login' => $login,
'password' => $password
)
);
I'm really stuck on this one. At the bottom of this post, I've attached the API documentation I'm working with. I want to catch the "message" when the response ("ask") isn't "Success". Seems reasonable enough, right? But when I do something like:
sfcSendError('Something went wrong. This is the message from the API: ' . $result->message);
I get a fatal error:
PHP Fatal error: Cannot access protected property SoapFault::$message
I found this seemingly related question on SO, so I tried changing "message" to "getMessage()" but (no surprise) that results in a different fatal error about calling an undefined function.
Here's my code snippet:
$client = mySoapClient(MODULE_SHIPPING_SFC_API_URL);
if (!$client) {
sfcSendError('could not make a SOAP connection. Halting until next CRON. [' . __FILE__ . ':' . __LINE__ . ']', 'SOAP Failure in cron job');
exit; //halt and wait for the next time cron runs
} else {
$HeaderRequest = array(
'customerId' => MODULE_SHIPPING_SFC_ACCOUNT,
'appToken' => MODULE_SHIPPING_SFC_TOKEN,
'appKey' => MODULE_SHIPPING_SFC_KEY
);
$reg = array(
'HeaderRequest' => $HeaderRequest,
'detailLevel' => 1,
'ordersCode' => $_query->fields['sfc_ordersCode']
);
$result = $client->getOrderByCode($reg);
if ($result->ask != "Success") {
sfcSendError('Something went wrong. This is the message from SFC: ' . $result->message, 'SOAP Failure in cron job');
$_query->MoveNext();
continue;
}
}
This is the referenced function:
function mySoapClient($url)
{
try {
$client = #new SoapClient($url, array(
'trace' => 1,
'exceptions' => 0,
'encoding' => 'UTF-8'
));
} catch (SoapFault $e) {
return 0;
}
return $client;
}
What am I doing wrong? Or is this a "bug" with the API where they really shouldn't be using "message" in their response?
I tried something like this :
try{
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$client = new SoapClient('http://83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl',
array('stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE));
));
print_r($client);
}
catch(Exception $e){
echo $e->getMessage();
}
and the result of my var_dump function is:
SOAP-ERROR: Parsing WSDL: Couldn't load from .... failed to load external entity...
how can i access the web service via soap ? thx.
This is the beginning of the xml :
I just downloaded the file from 83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl. I saved it on wsdl format and now i'm getting the functions
$client = new SoapClient("WebItem.wsdl", array('proxy_host' => "83.166.204.26",
'proxy_port' => 7147,
'proxy_login' => "xxxxxx",
'proxy_password' => "xxxxxxxx"));
echo "<pre>"; var_dump($client->__getFunctions()); echo "</pre>";
Firstly:
URL that you supply required Basic authentication. When using HTTP basic authentication, PHP will only send the credentials when invoking the service, not when fetching the WSDL.
You CAN get a wsdl, if basic authentication is required:
$login = 'xxx';
$password = 'xxx';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem?wsdl',
array(
'login' => $login,
'password' => $password
)
);
Secondly :
Your return XML does not look like valid WSDL file. Read SoapClient documentation page for proper usage - first argument of new SoapClient() must be URI of WSDL file or null for non-WSDL usage. (Here is an example of WSDL file ) May be you need to create SoapClient in non-WSDL mode?
I have sharepoint installed in my local windows server available through LAN. Now i am running a web-service in php on my local apache server like this:
<?php
//Authentication details
$authParams = array('login' => 'username', 'password' => 'password'); \
$listName = "TestList1";
$rowLimit = '150';
$wsdl = "http://www.blah.com/sharepoint/ListsWSDL.wsdl";
//Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName, 'rowLimit' => $rowLimit);
//Calling the GetListItems Web Service
$rawXMLresponse = null;
try{
$rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
echo 'Fault code: '.$fault->faultcode;
echo 'Fault string: '.$fault->faultstring;
}
echo '<pre>' . $rawXMLresponse . '</pre>';
//Loading the XML result into parsable DOM elements
$dom = new DOMDocument();
$dom->loadXML($rawXMLresponse);
$results = $dom->getElementsByTagNameNS("#RowsetSchema", "*");
//Fetching the elements values. Specify more attributes as necessary
foreach($results as $result){
echo $result->getAttribute("ows_LinkTitle")."<br/>";
}
unset($soapClient);
?>
<body>
</body>
</html>
But control is going to catch block with error displayed as:
Fault code: HTTPFault string: Unauthorized
Why is this happening?
First check the WSDL file, the server location is in the wsdl file, right at the bottom. Please make sure this server location is correct.
Please activate "Basic authentication" (in IIS6) for this sharepoint site you are trying to access.
Have you enabled the basic authentication in IIS ?
Look at this link :
http://blogs.iis.net/nitashav/archive/2010/02/22/iis6-0-ui-vs-iis7-x-ui-series-basic-authentication.aspx
Check your credentials.
Try to change IIS Authentication Settings to Kerberos.