Welcome Guest, Not a member yet? Register   Sign In
how to use soap in CI?
#1

[eluser]chmod[/eluser]
I download the nusoap and unzip it ,put the lib to system/libraries.
then I create a custom class which is named Nusoap_lib in system/libraries.
-----------------------------------------------
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Nusoap_lib
{
function Nusoap_lib()
{
require_once(BASEPATH.'libraries/lib/nusoap'.EXT);
}
}
?>
-----------------------------------------------

then I create a Server part on the test server which is named webservice.php,like this:
-----------------------------------------------
<?
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('add');
function add ($a,$b){
if (!$a || !$b ){
return new soap_fault('Client','','Put add values!');
}
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
-----------------------------------------------

access http://192.168.1.134/webservice.php,output is :

===============================================

This XML file does not appear to have any style information associated with it. The document tree is shown below.


<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<SOAP-ENV:Fault>
<faultcode xsi:type="xsdConfusedtring">SOAP-ENV:Client</faultcode>
<faultactor xsi:type="xsdConfusedtring"/>
<faultstring xsi:type="xsdConfusedtring">method '' not defined in service</faultstring>
<detail xsi:type="xsdConfusedtring"/>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
===============================================

so,I create the soap client in system/controller/webservice/soapc.php,like this:
-----------------------------------------------
class Soapc extends Controller{
function Soapc(){
parent::Controller();
$this->load->library('Nusoap_lib');
}

function index(){
$this->client = new soapclient('http://192.168.1.134/webservice.php');

if ($this->client->fault){
return $this->client->fault;
}else{
$param = array (3,4);
return $this->client->call('add',$param);
}
}

}
-----------------------------------------------

but the output is like this:

A PHP Error was encountered

Severity: Warning

Message: SoapClient::SoapClient(http://192.168.1.134/webservice.php) [function.SoapClient-SoapClient]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error

Filename: game/soapc.php

Line Number: 18


A PHP Error was encountered

Severity: Warning

Message: SoapClient::SoapClient() [function.SoapClient-SoapClient]: I/O warning : failed to load external entity "http://192.168.1.134/webservice.php"

Filename: game/soapc.php

Line Number: 18


Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://192.168.1.134/webservice.php' in D:\AppServ\www\gkuaiche\demo\application\controllers\game\soapc.php:18 Stack trace: #0 D:\AppServ\www\gkuaiche\demo\application\controllers\game\soapc.php(18): SoapClient->SoapClient('http://192.168....') #1 [internal function]: Soapc->index() #2 D:\AppServ\www\gkuaiche\demo\codeigniter\CodeIgniter.php(224): call_user_func_array(Array, Array) #3 D:\AppServ\www\gkuaiche\index.php(117): require_once('D:\AppServ\www\...') #4 {main} thrown in D:\AppServ\www\gkuaiche\demo\application\controllers\game\soapc.php on line 18
#2

[eluser]chmod[/eluser]
i use the PHP's soap,like this:

soap serverConfusedystem/controller
controller:
-------------------------------
&lt;?
class Webservice extends Controller{
function Webservice(){
parent::Controller();
}

function index(){
function add($a,$b){
print $a + $b;
}

$server = new SoapServer(null, array('uri' => "http://go.killer.com/"));
$server->addFunction('add');
$server->handle();
}
}
?&gt;
-------------------------------


soap client:
-------------------------------
class Soapc extends Controller{
function Soapc(){
parent::Controller();
}

function index(){
try {
$soapc = new SoapClient(null,array("location" => "http://192.168.1.134/webservice/","uri"=>"http://go.killer.com/"));
return $soapc->add(3,3);
}catch (Exception $e){
echo 'Error Caught';
}
}

}
-------------------------------


the output is :

Error Caught


is there any error in my code?
#3

[eluser]Usama Ahmed[/eluser]
function add($number1,$number2){
return ($number1 + $number);
}


You need to write the definition of your soap function 'add' inside your controller Webservice.
#4

[eluser]ken.sniper[/eluser]
hi all,how to use model in server? I try to get model.
Code:
$querystr = "select name from sso_member where id=1"
            $query = $this->regcheck_model->execquery($querystr);
            $row = $query->row();
            return "result:".$row->name;
error:
Using $this when not in object context

later,I try:
Code:
$CI =&get;_instance();
            $querystr = "select name from sso_member where id=1"
            $query = $CI->regcheck_model->execquery($querystr);
            $row = $query->row();
            return "result:".$row->name;
and return: result:0;
#5

[eluser]Unknown[/eluser]
I have exactly the same problem with models as ken.sniper.
Has anybody an idea how to get around this?

I'm using the Zend_Soap classes (as he does as far as I can see).




Theme © iAndrew 2016 - Forum software by © MyBB