Call Web Service Method Via Corona Application

Hello developers …

i want to call web service method written on ASP.Net (or PHP ) can i do that via corona application ? and if yes how can i do it ??

with respect

thanks in advance
[import]uid: 74537 topic_id: 24752 reply_id: 324752[/import]

Web services are called using the:

network.request()

API call.

It sends HTTP GET, POST, PUT, DELETE and HEAD requests to the webserver.

Depending on the type of web server (SOAP, REST, etc.) you may or may not have to do extra work to login, authenticate yourself etc.

REST is pretty much the easiest since it’s basically build a URL and do a get request:

http://yoursite.com/api/search.php?q=some+query+string&maxresults=10&orderby=desc&output=json

You would take a string like that and make the network.request api call:

network.request(URL,"GET",functionToHandleResponse)  

You need a function you write to go with it, that I called “functionToHandleResposne” above. network.request doesn’t wait around for the webserver to respond, but when it does and the data is downloaded, this function is triggered and you use it to process the results.

Typical web services either return XML or JSON as data formats (others are possible, but those are the two most common). JSON is the easiest to work with because we have native calls to parse the JSON data and turn it into a native Lua table using the Key-Value pairs that we are used too. XML requires a parser and most of the ones out there also give you a Lua table, but the keys are typically numeric indexes and are harder to traverse (data[1].child[2].description as opposed to data.description you get with JSON)

But both are doable. Other formats you would be on your own to parse. [import]uid: 19626 topic_id: 24752 reply_id: 100427[/import]

Hi ,

could you please give me any example, how to call a wcf werb service in corona?

eg. my web service is http://localhost/SAMIPlanning/SAMIPlanningAccountService.svc and it has a web method called ‘GetATSUser()’, this method accept 3 parameter and return boolean value.

Thanks in advance
Saurav [import]uid: 163804 topic_id: 24752 reply_id: 115796[/import]

See my blog post:

http://omnigeek.robmiracle.com/2012/04/15/using-corona-sdk-with-rest-api-services/ [import]uid: 19626 topic_id: 24752 reply_id: 115808[/import]

Thaks for your reply.

But I am still fighting with .svc (WCF service extension).

In your blog, you are using PHP, but I want to use a wcf service with .svc extension.

Thanks
Saurav [import]uid: 163804 topic_id: 24752 reply_id: 115875[/import]

From the Corona side, it shouldn’t matter if its .asp, .net, .php, or any other format. If it’s a web service, it should respond to HTTP GET and PUT statements the same. So from your perspective the output is the output and you’re going to use network.request() the same way regardless of what technology is outputting the data.

In other words, ignore the PHP parts of the blog and focus on the app side network.request() parts.

In the network.request() listener function, you will want to print out to the console the event.response variable and see what data the server is sending back… is it JSON or XML where you can use library calls to turn it into a lua table? or is it some other data that you have to figure out how to parse into various variables.
[import]uid: 19626 topic_id: 24752 reply_id: 115908[/import]

Thanks a lot,

I have resolved the issue. I have created a RESTful web service in MVC and its working fine with Corona.

Saurav [import]uid: 163804 topic_id: 24752 reply_id: 115981[/import]

Thx [import]uid: 74537 topic_id: 24752 reply_id: 119740[/import]

Thx [import]uid: 74537 topic_id: 24752 reply_id: 119740[/import]