Creating SOAP service, issue with Controller |
[eluser]stevefink[/eluser]
Hi all, I created a demo SOAP service that I plan to build out a complete Web API for on top of Code Igniter for my application. My SOAP service works just fine when I slap together some scripts, however, when it comes time to add the stuff into CI, stuff breaks. An example of my Controller looks like the following: Code: <?php When I call my client side code, I get the following error output: Fatal error: SOAP Fault: (faultcode: SOAP-ENV:Server, faultstring: SoapServer::addFunction() [<a href='function.SoapServer-addFunction'>function.SoapServer-addFunction</a>]: Tried to add a non existant function 'Demo') in /www/ll-prod-api/api/soap.php on line It appears it doesn't recognize my function Demo() at all. I've also tried using something similar to: Code: $server->addFunction($this->Demo); It would be great if I can get my SOAP functionality working in this fashion as then I can leverage my models for the business logic of the web service. Then I can create rest.php, xmlrpc.php and so on. The beauty of MVC. If anyone can point me in the correct direction, that would be sweet. Thanks all!
[eluser]stevefink[/eluser]
Hate to reply to my own post, but I've made some progress which looks positive. I am indeed getting a respone back from my SOAP server with the right string. However, SOAP still throws an Exception because Code Igniter throws the following output, Code: <html> This is what it typically throws out for 404s or whatever. However, in this case, there isn't a URL. I just have the URI convention of http://foo/soap where SOAP is my controller. It is indeed there. Any idea how to correct this behavior? I'm also seeing the following in CI logs: ERROR - 2008-06-22 21:09:40 --> 404 Page Not Found --> ERROR - 2008-06-22 21:09:40 --> Severity: Warning --> Cannot modify header information - headers already sent by (output started at /www/ll-prod-api/system/application/controllers/soap.php:14) /www/ll-prod-api/system/application/errors/error_404.php 1 It doesn't indicate which page is 404 -- as far as the headers already sent, that's the SOAP server doing so.. then CI tries to send additional ones with the 404 page.
[eluser]Unknown[/eluser]
I'm not sure if you figured this out yet or if this is even your problem because you've got a lot of things going on there. You can't have any headers (i.e. <html>...) or whitespace before your server. I've only been working with SOAP for about 2 days, so, I really don't know much... Check this out for a demo: soapclient.php Code: <?php soapserv.php Code: <?php Make sure you change the DB user and Code: $c = new soapClient('http://localhost/soap/soapserv.php?wsdl'); You'll need the nusoap from sourceforge if you don't have it. Get the server working and then put one space at the top of the file. You'll get the same error. So you can't wrap the server in html either. I dunno, hope that helps someone. It would have saved me some time if I found that out yesterday. Also, you can use the sql file I attached to build a MySQL sample database to work with the server. The data is pretty good, saves me a lot of time creating dummy data. ---Edit: The 150k limit blocked the .sql sample database. I've changed the extension to txt to fix that.
[eluser]Nathan Pitman (Nine Four)[/eluser]
[quote author="stevefink" date="1214199569"]I just have the URI convention of http://foo/soap where SOAP is my controller. It is indeed there. Any idea how to correct this behavior?[/quote] Have you tried adding the controller/function and intended URL to your routes.php file? Would be interested to know if you got this all working?
[eluser]Unknown[/eluser]
I want to offer simple method for those who'll get here from google, because I haven't seen anything like this when was looking for advice. Creating SOAP services even with CodeIgniter is easy. You don't need nusoap, don't waste your time. I'll take code from OP. Code: <?php Now you can call any public function from your Soap controller with Soap request. If you need hidden implementation - use private or protected. Anyway you won't be able to call function which wasn't described in WSDL. And remember that return values must be properly described in WSDL. If you have any difficulties (and you will, I promise) -- read specs, use gui tools, for example Eclipse plugin which provides gui for designing WSDL (built-in in PDT afaik) and soapUI for testing your service. Links: http://wiki.eclipse.org/index.php/Introd...SDL_Editor http://www.soapui.org/
[eluser]tastatura[/eluser]
Ok, I have one question. I have to implement SOAP client in Codeigniter. Every xml request has authentication header : user, pass, licenece. There aree several methods on server side which I can call. I am thinking on creating one model for every method on server side, but how can i do that using DRY principle for Authentication ? Thanks!!!
[eluser]danmontgomery[/eluser]
Put the authentication in the construct. Code: public function __construct() { I prefer to make api calls with __call, so that I don't have to define a method for each soap method. Code: public function __call($method, $args) { If you need to pass authentication in each call, you can skip the construct part and just add those parameters in __call, where you call the method |
Welcome Guest, Not a member yet? Register Sign In |