Receive error when running basic nuSOAP tutorial - php

I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!

The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server

You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');

Related

Is it required to include any files from gomoob:php-pushwooshto to run a PHP program to send push notifications to iPhone?

I want to send push notifications to iPhone devices by writing PHP code for it.
gomoob:php-pushwoosh is a PHP Library that easily work with the pushwoosh REST Web Services.
This is the URL for gomoob:php-pushwoosh
As per the instructions I've installed gomoob:php-pushwoosh on my local machine using Composer at location '/var/www/gomoob-php-pushwoosh'
I wrote following code in a file titled sample_1.php which is present at location '/var/www/gomoob-php-pushwoosh/sample_1.php'
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require __DIR__.'/vendor/autoload.php';
// Create a Pushwoosh client
$pushwoosh = Pushwoosh::create()
->setApplication('XXXX-XXX')
->setAuth('xxxxxxxx');
// Create a request for the '/createMessage' Web Service
$request = CreateMessageRequest::create()
->addNotification(Notification::create()->setContent('Hello Jean !'));
// Call the REST Web Service
$response = $pushwoosh->createMessage($request);
// Check if its ok
if($response->isOk()) {
print 'Great, my message has been sent !';
} else {
print 'Oups, the sent failed :-(';
print 'Status code : ' . $response->getStatusCode();
print 'Status message : ' . $response->getStatusMessage();
}
?>
But I'm getting following error for it :
Fatal error: Class 'Pushwoosh' not found in /var/www/gomoob-php-pushwoosh/sample_1.php on line 9
At the Link they have not mentioned that any file needs to be included into the code. They have only written sample code program. I've used that program as it is but getting error for it.
So can someone please help me in running this program?
The class you want resides in a namespace, so you need to instruct PHP to "import" it (and other classes) from there; add this to the beginning of your script:
use Gomoob\Pushwoosh\Client\Pushwoosh;
use Gomoob\Pushwoosh\Model\Request\CreateMessageRequest;
use Gomoob\Pushwoosh\Model\Notification\Notification;
require __DIR__.'/vendor/autoload.php';

Getting incident records from ServiceNow using PHP

I am trying to use PHP to connect to ServiceNow and retrieve incident records.
I tried to use the code below but somehow I receive errors:
<?php
$credentials = array('login'=>'user', 'password'=>'pass');
$client = new SoapClient("https://blah.com/incident.do?WSDL", $credentials);
$params = array('param1' => 'value1', 'param1' => 'value1');
$result = $client->__soapCall('getRecords', array('parameters' => $params));
// result array stored in $result->getRecordsResult
?>
I am always getting:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https : // blah . service-now . com / incident.do?WSDL' : failed to load external entity "https : // blah . service-now.com / incident.do?WSDL" in /var/www/index.php:3 Stack trace: #0 /var/www/index.php(3): SoapClient->SoapClient('https://blah.ser...', Array) #1 {main} thrown in /var/www/index.php on line 3
Of course I use the subdomain I want instead of blah. But let's assume it's blah.
Please help me. Is this code ok? Where do I place my username? On the user area? or in the login area? What about param1 and value1, which one of these do I need to change?
Yes, I have permission to do this on my servicenow instance, I can do other things regarding soap and wsdl.
goto "System Properties" -> "Web Services" and make sure that
"Require authorization for incoming WSDL requests." ist set to NO
If this flag is set to Yes you will not be able to directly create a SoapClient within PHP the way you described it.

Issue in curl connecting with Ip address in zend

Dear Supporter,
$data=array(
"themeName"=>"gghg"
);
$adapter = new Zend_Http_Client_Adapter_Curl();
$adapter->setConfig($curlOption);
//instantiate the http client and add set the adapter
$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");
$client->setAdapter($adapter);
//add the post parameters from our config file (the authentication part)
$client->setParameterPost($data);
//perform the post, and get the response
$response = $client->request(Zend_Http_Client::POST);
Error :
Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied' in /var/www/html/ursify/Source/ursify.com/library/Zend/Uri/Http.php:
I am trying to create client object "$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");"
Where i am doing wrong ? Help me
Seems everything fine. I've tested your code and there are no errors except timeout in cUrl call. I've tested with ZF 1.12.7

create PHP soap web service

I am very new to PHP and weak in programming.
I need to create a web service using PHP.
The main purpose is to allow user to enter their info and validate it at the backend database.
User enter their info in HTML in an array of
$_SESSION['ctform'][]
detail.php (client)
$wsdl = "http://localhost/detail_logic.php";
$client = new soapclient($wsdl);
$response = $client->_call('process_si_contact_form', array($_SESSION['ctform']));
detail_logic.php (server)
function process_si_contact_form()
{
//Process and validate the info
//Data base connection
}
$ss = new SoapServer(null, $_SESSION['ctform']);
$ss->addFunction("process_si_contact_form");
$ss->handle();
I have many error like:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/detail_logic.php'
Please help and Thank you.
I think, You need a wsdl file for creating a Soap based server, So client can be communicate to it. Also client will communicate through wsdl file not directly with Url. See http://php.net/manual/en/sca.examples.understanding-wsdl.php and http://in1.php.net/manual/en/soapclient.soapclient.php

XMLRPC Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 10 seconds

I've Googled everywhere but no one has posted a solution, they all say to set the timeout in the config but how do you do this?
How do I reset/override this setting from my XMLRPC client or server?
Here is what I'm trying:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
$client = $server->getProxy();
// Increasing the timeout
$client->setConfig(array('timeout'=>30));
Here is the error:
Fatal error: Uncaught exception 'Zend_XmlRpc_Client_FaultException'
with message 'Method "setConfig" does not exist'
in /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php:370
Trying to pass as arg:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc', array('timeout'=>30));
Here is the error:
Catchable fatal error: Argument 2 passed to
Zend_XmlRpc_Client::__construct() must be an
instance of Zend_Http_Client
Found the solution and here it is:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
// Get the HTTP Client used by the XMLRPC client
$http_client = $server->getHttpClient();
// Increasing the HTTP timeout
$http_client->setConfig(array('timeout'=>30));
$client = $server->getProxy();
One Line works for me as well:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
// Get the HTTP Client used by the XMLRPC client and increasing the HTTP timeout
$server->getHttpClient()->setConfig(array('timeout'=>30));
$client = $server->getProxy();
Zend documentation specifies the configuration parameters that you are allowed to use. I would guess that you can simply increase the timeout from 10 seconds to 20 or 30. Whatever is appropriate for you.
$client = new Zend_Http_Client('http://example.org', array('timeout' => 30));
or:
$client->setConfig(array('timeout'=>30));
UPDATE - Zend_Http_Client is used by Zend_XmlRpc_Client. You can set and access the Zend_Http_Client via the Zend_XmlRpc_Client object.
$xmlrpc_client = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
$xmlrpc_client->getHttpClient()->setConfig(array('timeout'=>30'));
I haven't tested this so I don't know that it will work but you can also pass in your own Zend_Http_Client object to a Zend_XmlRpc_Client object using the setHttpClient() method as described (rather arcanely) at the bottom of the Zend documentation page for Zend_XmlRpc_Client.
Whatever client you're using:
$client->getHttpClient()->setConfig(array('timeout'=>30));
where $client could be a Rest or Soap Client.
Also, one of the answers here has a minor error that causes pain:
client->getHttpClient()->setConfig(array('timeout'=>30')); - remove single quote after 30
Those answers are alright, though since Zend HTTP 2.0 (released in 2012 - see diff) it is :
$client->getHttpClient()->setOptions(array('timeout'=>30));

Categories