(04-28-2015, 09:06 PM)algenza Wrote: you must load nusoap library
Ok, its working well now. but i have the example of this library.
that means will give me "Fruits apple 4".
I have to read a DB or whatever and then send it by WSDL to a Client. im stuck in this!
Im going to write whole my code in controller & ... except the NuSoap library (because its same).
HOW can i get the data(source isnt important right now) , convert to WSDL and then response to the Client?
My Controller
PHP Code:
class NuSoapServer extends CI_Controller {
function __construct()
{
parent::__construct();
$ns = base_url();
$this->load->library("Nusoap_library");
$this->load->library("Master");
$this->server = new soap_server(); // it is a soap server object
$this->server->configureWSDL("SOAP", $ns); // configure wsdl
$this->server->wsdl->schemaTargetNamespace = $ns; // namespace for the server
}
function index()
{
$ns = base_url();
$input_array = array ('count' => 'xsd:integer', 'type' => "xsd:string"); // method parameters
$return_array = array ("fruit" => "xsd:string");
//soapAction
$this->server->register(
'Master.fruits',
$input_array,
$return_array,
"urn:SOAPServerWSDL",
"urn:".$ns."/fruits",
"rpc",
"encoded",
"Fruit Types"
);
$this->server->service(file_get_contents("php://input")); // reading raw data
}
function client(){
$this->client = new nusoap_client(base_url()."/index.php/interface/nusoapserver?wsdl", true);
$this->load->view("client");
}
}
My master.php in libraries folder
PHP Code:
class Master {
public function fruits($count, $type)
{
switch($type)
{
case 'red':
return $count." Apple";
break;
case 'yellow':
return $count." banana";
break;
}
}
My Client.php in view folder
PHP Code:
<?php
$error = $this->client->getError();
if ($error)
{
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $this->client->call("Master.myfile", array("count" => 4, "type" => "red"));
if ($this->client->fault)
{
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $this->client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>Correct result</h2><pre>";
echo $result;
echo "</pre>";
}
}