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


Messages In This Thread
how to use soap in CI? - by El Forum - 05-10-2008, 02:53 AM
how to use soap in CI? - by El Forum - 05-10-2008, 03:32 AM
how to use soap in CI? - by El Forum - 05-21-2008, 12:37 AM
how to use soap in CI? - by El Forum - 07-20-2009, 07:36 AM
how to use soap in CI? - by El Forum - 07-26-2010, 11:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB