Welcome Guest, Not a member yet? Register   Sign In
Webservices
#1

[eluser]Kurtis[/eluser]
hi there,
Im having trouble consuming a webservice. has anyone have some sample code how to do a webservice with CI. I installed the nusoap library but CodeIgniter uses a segment-based approach I can't figured out how to do this.
#2

[eluser]shaffick[/eluser]
I dont know...I imagine (if i remember nusoap correctly) it would go something like this.....maybe? just use it as a library. call it from your controllers, that's an option.

Code:
class SoapWoot {

    var $soapFile         = '/PATH_TO_NUSOAP/nusoap.php';
    var $wsdlUrl         = 'URL_TO_WEBSERVICES';
    var $wsdlOptions    = array('trace' => 1, 'exceptions' => 1);
    var $wsdlUsername    = '';
    var $wsdlPassword    = '';
    var $soapObj        = NULL;
    var $errorString  = NULL;
    // add more stuff here, maybe
    
    function SoapWoot() {
        
        require_once($this->soapFile);
        $proxy = new SoapClient2($this->$wsdlUrl, $this->wsdlOptions);  // for php5, use new SoapClient() for php < 5
        $this->soapObj = $proxy->GetProxy();
        $this->soapObj->setCredentials($this->wsdlUsername, $this->wsdlPassword);  // depends on the webservice used
    
    }
    
    function webServiceFunctionToCall($params) {
        // do stuff here
    }
    
}
#3

[eluser]Kurtis[/eluser]
nice, but I have more issue with the server part.
I have something like that

Code:
class Services extends Controller {

    function Services() {
        parent::Controller();
        $this->load->library("nusoap");
        $this->load->helper('url');
    }

    function index() {

                if($this->uri->segment(3) == "wsdl") {
                $_SERVER['QUERY_STRING'] = "wsdl";
            } else {
                $_SERVER['QUERY_STRING'] = "";
            }

        $this->server = new soap_server;

        $this->server->configureWSDL('myname', 'urn:idorder');

               $this->server->register("getIdOrder",
                       array('order' => 'xsd:string'),
                       array('return' => 'xsd:string'),
                       'urn:idorder',
                       'urn:myname#getIdOrder'
                       );

          $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
       $this->server->service($HTTP_RAW_POST_DATA);

        }

           function getIdOrder($order) {
                // some stuffs ...........
          return $reponse_xml->saveXML();
           }

    

}
the idea is to receive an string (xml) do some stuff with it and return the response, but
I tested it outside CI, it worked but inside the controller I got nothing be null as response.
with the link for the wsdl service like this : http://hostname/index.php/services?wsdl
is there a way to change it?
#4

[eluser]shaffick[/eluser]
Check out this link http://ellislab.com/codeigniter/user-gui...input.html

more specifically, $this->input->server()

Instead of
Code:
if($this->uri->segment(3) == "wsdl") {
                $_SERVER['QUERY_STRING'] = "wsdl";
            } else {
                $_SERVER['QUERY_STRING'] = "";
            }

try
Code:
$queryString = (trim($this->input->server('QUERY_STRING')) == 'wsdl') ? 'wsdl' : '';

It doesn't use the segment thing altogether and does what you are trying to achieve

Use $queryString to reference to the query string for use with code below that check.
#5

[eluser]Kurtis[/eluser]
I got this error msg:
Error: wsdl error: XML error parsing WSDL from http://xyz../services/index/wsdl on line 76: Attribute without value

how exactly does I use $queryString later?
#6

[eluser]shaffick[/eluser]
Oh, I think you may have misunderstood my post.

$queryString is actually for the check and returns "wsdl" or empty.

You only use it if you want to check whether the query string is wsdl or not. It is unrelated to your XML parsing problem.

Makes sense? Lemme know.
#7

[eluser]Kurtis[/eluser]
yeah you're right, it's just a pain debugging this stuff grrrrrr
#8

[eluser]Nathan Pitman (Nine Four)[/eluser]
Hi Kurtis. I'm trying to get a basic CI NuSOAP example up and running and I'm having similar problems to those which you describe here. Is there any chance you might be willing to share some examples if you eventually got this all working? For example the controller, what entries you added to routes and whether you were using htaccess for clean URLs etc???




Theme © iAndrew 2016 - Forum software by © MyBB