i am new to webservices,
I have created a basic stockmarket webservice, I have successfully created the server script for it and placed it in my server, Now I also creted a clent script and accessed it hruogh the same server.. Is it valid ? can boh files be accesed from the same server? or do I have to place them in different servers? If yes Then Y? If No then why do i get the blank page?
I am using nusoap library for webservice.
When I use my cleint script from my local machine I get these errors
"Deprecated: Assigning the return
value of new by reference is
deprecated in
D:\wamp\www\pranav_test\nusoap\lib\nusoap.php
on line 6506
Fatal error: Class 'soapclient' not
found in
D:\wamp\www\pranav_test\stockclient.php
on line 3"
stockserver.php at server
<?php
function getStockQuote($symbol) {
mysql_connect('localhost','root','******');
mysql_select_db('pranav_demo');
$query = "SELECT stock_price FROM stockprices "
. "WHERE stock_symbol = '$symbol'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
return $row['stock_price'];
}
require('nusoap/lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('stockserver', 'urn:stockquote');
$server->register("getStockQuote",
array('symbol' => 'xsd:string'),
array('return' => 'xsd:decimal'),
'urn:stockquote',
'urn:stockquote#getStockQuote');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
stockclient.php
<?php
require_once('nusoap/lib/nusoap.php');
$c = new soapclient('http://192.168.1.20/pranav_test/stockserver.php');
$stockprice = $c->call('getStockQuote',
array('symbol' => 'ABC'));
echo "The stock price for 'ABC' is $stockprice.";
?>
please help...
Please post a piece of source code.
Yes you can access your webservice from a client which is also located on the same server.
For testing webservices I recommend SoapUI, which is available for all platforms.
I recommend to use the build in soap extension of php then nusoap, it's an rather old library.
I'm really very new to PHP but i found the same error when i was working with nusoap.
what i understood that in php 5 you can't assign the return value of new object using referencing ( using the & operator) so simply... Remove it :D...
I did that i it worked.
to initiate a soap client with the new php version 5x - there is a conflict with the PHP5 soap library and the NuSoap library.
download the latest nusoap.php library for PHP version 5.3.x (you can get this from sourceforge)
Change the following class call in your client to:
$c = new soapclient
to
$c = new nusoap_client
You may also want to add the following to your PHP ini file.
[nusoap_deprecated]
; Turn off deprecated messages on rendered pages
error_reporting = E_ALL & ~E_DEPRECATED
Related
I am using this PHP Kafka client library. Our Kafka is installed on server A and producer from different servers adding data in this using Java code, and now I am trying to consume data via PHP from server B. I need to pass the username and password to access data but in documentation, I am not getting any way to pass the username, password, and bootstrap server.
Java team using following details to add data in kafka
spring.kafka.bootstrap-servers=<value-here>
spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='<username>' password='<password>';
Now same, I am trying to achieve via PHP. How I can pass these parameters with my PHP code to consume data.
According to the documentation, try to do:
<?php
$conf = new \RdKafka\Conf();
$conf->set('sasl.jaas.config', "org.apache.kafka.common.security.plain.PlainLoginModule required username='<username>' password='<password>'");
$conf->set('security.protocol', "SASL_SSL");
$conf->set('sasl.mechanism', "PLAIN");
$consumer = new \RdKafka\Consumer($conf);
$consumer->addBrokers("<kafka_servers_list>");
Following is the solution of problem.
$conf = new RdKafka\Conf();
$conf->set('bootstrap.servers', '<pass-server-here>');
$conf->set('sasl.username', '<username>');
$conf->set('sasl.password', '<password>');
$conf->set('security.protocol', 'sasl_ssl');
$conf->set('sasl.mechanism', 'PLAIN');
$conf->set('group.id', 'anygroupID');
$conf->set('debug', 'all');
$rk = new RdKafka\Consumer($conf);
I am trying to re-write a Drupal module that has fallen behind the API of the gateway it connects to.
A stripped back version of the code I think is causing the problem is as follows:
$namespace = ($this->testing) ? 'https://api.sandbox.ewaypayments.com/' : 'https://api.ewaypayments.com/';
$endpoint = $this->url;
$httpUsername = $this->user_name;
$httpPassword = $this->password;
$client = new nusoap_client($endpoint, TRUE);
$client->setCredentials($httpUsername, $httpPassword, 'basic');
$client->response_timeout = 50;
$result = $client->call($operation, array('request' => $params), $namespace);
The $result is consistently false. If I put anything like this into my code it also consistently returns empty:
$error = $client->getError();
watchdog('connection_message', $error);
I'm a bit out of my depth and without any error messages in my Apache logs or in the Drupal watchdog I cannot see a way forward.
1. Turn on PHP error reporting if it's not already on.
Check that the error_reporting, display_errors settings in your php.ini file are set to E_ALL and On respectively when you are developing locally. You can also add these directives at the beginning of your PHP script to set them at run time:
error_reporting(E_ALL);
ini_set('display_errors', 'On');
2. Catch NuSOAP errors like this:
$result = $client->call($operation, array('request' => $params), $namespace);
if ($client->fault) {
echo 'Error: ';
print_r($result);
} else {
// check result
$err_msg = $client->getError();
if ($err_msg) {
// Print error msg
echo 'Error: '.$err_msg;
} else {
// Print result
echo 'Result: ';
print_r($result);
}
}
3. Verify you are using the correct API parameters and endpoint:
From the eWAY API reference, your endpoints are:
https://api.ewaypayments.com/soap.asmx (production)
https://api.sandbox.ewaypayments.com/soap.asmx (sandbox)
4. Similar eWAY API projects that you can reverse-engineer:
Commerce eWAY for Drupal (last version is Mar. 2014)
eWAY-RapidAPI (uses JSON and cURL)
eWay-PHP-API (uses XML and cURL)
eWay Payment Gateway (uses SOAPClient)
There are a couple of things I would like to say in this case.
First, why do you have to use that library ? You can use Zend_Soap_Client (if you don't have it you can install it using composer:
http://framework.zend.com/downloads/composer (look for zendframework/zend-soap)
Then, you can download a trial version of PHPStorm. Its debugging tools when used with http://xdebug.org are really awesome, you can inspect the entire variable and environment space in runtime.
Finally, you can use a friendly error managing tool like http://raygun.io, you insert a few lines of code, create a trial account in there, and in minutes you get all errors that are happening in your application.
In your case, you can see for example the current value of $operation, which seems the function being called on the webservice.
Here's the code for inspecting all functions being offered in a webservice using Zend_Soap_Client:
$endpoint = 'http://your.example.endpoint/?wsdl';
$soapClient = new Zend_Soap_Client($endpoint);
$functions = $soapClient->getFunctions();
var_dump($functions);
Since you are using SOAP requests your endpoint is incorrect, it should be https://api.ewaypayments.com/soap.asmx or
https://api.sandbox.ewaypayments.com/soap.asmx
For better performance you may think to disable nusoap debugging.
To check, edit the /include/nusoap/nusoap.php file and set the debug level to 0, like this:
['nusoap_base']->globalDebugLevel = 0;
One step even further is to remove all lines that start with:
$this->debug(
or
$this->appendDebug(
Source:
http://kb.omni-ts.com/entry/245/
You could give this module a try: https://www.drupal.org/project/eway_integration
We are currently working with eWay to test this module together. It works with Drupal Commerce and implements eWay's RAPID 3.1 API and is PCI compliant.
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');
I have seen little to know instruction on using php to develop a client website to make remote calls to JiRA.
Currently I'm trying to make a soap client using JSP/Java to connect to a local jira instance. I would like to create and search issues that is all. We are currently having some problems using Maven2 and getting all the files we need from the repository since we are behind a major firewall(yes I've used the proxy).
I have a lot of experience with PHP and would like to know if using the PHP soapclient calls can get the job done.
http://php.net/manual/en/soapclient.soapclient.php
Yes it can be done, using SOAP or XML-RPC.
Using the APIs is pretty much straight forward - have a look at the API documentation to find the right functions for you. your code should look something like :
<?
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
...
... # get/create/modify issues
...
?>
Example of adding a new comment:
$issueKey = "key-123";
$myComment = "your comment";
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
$soapClient->addComment($token, $issueKey, array('body' => $myComment));
Example of creating an issue:
$issue = array(
'type'=>'1',
'project'=>'TEST',
'description'=>'my description',
'summary'=>'my summary',
'priority'=>'1',
'assignee'=>'user',
'reporter'=>'user',
);
$soapClient = new SoapClient("https://your.jira/rpc/soap/jirasoapservice-v2?wsdl");
$token = $soapClient->login('user', 'password');
$soapClient->createIssue($token, $issue);
Note that you need to install php-soap in linux (or it's equivalent in windows) to be able to use the SOAP library.
I'm trying to write a simple web service server and client using nusoap. I think my server works fine because a VB.NET client can call it. However, the PHP client has a very long loading time and does not give any output.
server1.php
<?
require_once("nusoap/lib/nusoap.php");
$ns="localhost/";
$server = new soap_server();
$server->configureWSDL('TaxCalculator', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
$server->register('TaxCalc', array('amount'=>'xsd:string'),array('return'=>'xsd:string'),$ns);
function TaxCalc($amount) {
$tax = $amount * 0.5;
return new soapval('return', 'xsd:string', $tax);
}
$server->service($HTTP_RAW_POST_DATA);
?>
client1.php
<?
require_once('nusoap/lib/nusoap.php');
$client=new soapclient('http://localhost/server1.php?wsdl', 'wsdl');
echo $client->call('TaxCalc', array('amount'=>'15.00'));
?>
I'm using PHP Version 5.2.6 and nusoap version 0.9.5.
I'd say use whatever works.
I have used nusoap.php,v 1.114 and it works for me.
The nuspoap_client call I have is different from what you have above. Yours does not have a paramter for what port to use.
$client = new nusoap_client("http://127.0.0.1:1024/soap/IApp", false,
$proxyhost, $proxyport, $proxyusername, $proxypassword);
The 2nd parameter above says not to use a wsdl file.
I am guessing that maybe your VB client uses the same approach.
Your code looks like it wants to use a local wsdl file.
Alternatively maybe there is a permissions issue where VB is allowed to access the soap port and PHP is not. (doubt it as everything is local)