Need advice on .NET webservice method from Android application - android

I am accessing .NET webservice methods from my Android application using Java SOAP jar.
I am getting response for a specific webservice method as an array .
Do we have an API within the Java SOAP library to convert the response from array to XML(String) ?
Also , since using the external SOAP jar is around 90 KB in size , would like to know of an alternative approach by which we can access webservice , maybe a RESTful Web Services implementation or anything of a similar type, which wont require to add an external jar to the Android application & hence reduce the application size.
It would be nice if someone can come up with the changes to be done on the server end for implementing the RESTful WebServices in .NET & the client code for the same which I think will be only a HTTP connection .
Kindly provide your valuable *comments/code snippet*s on the same.

Try using "KSoap2" it is leightweight and it is open source so you add just the libraries to your project and you can implement your method returning pure XML.
http://ksoap2.sourceforge.net/

Related

iOS & bootstrap connecting to external database

I am doing some investigation into developing a iOS App, Android App as well as a bootstrap website. This is really at the early stages of the project and I have been out of software development for a number of years so I am a little rusty, so please forgive me for my questions.
To connect to an external database and/or external C# code from an App, I presume you need to use a webservice? Is this the only way to do this?
What format is required? JSON?
From a bootstrap website, how would I go about doing the same thing? Via a AJAX call to a webservice?
Do most Apps use the internal storage/database for storing data? (I know that's a very general question, I am just trying to get a feel for things)
Thanks for your help.
You will need a web service. Theoretically you can connect to the databases directly with android and iOS, but that's less secure, and making changes is difficult. For example, if you ever want to rename a column in your database, you would break your existing apps. However, if you use a webservice, you can update the webservice to report the column under it's old name.
You can use whatever format you want, but I would strongly recommend JSON. There are lots of powerful, fast parsers out there to handle serializing and deserializing JSON strings out there, and some networking clients that will even handle the translation automatically for you.
You would indeed use an AJAX call.
Yes, that is very general, but most apps will. It really varies what kind of data you need to persist. If you're just looking to cache a feed until the next launch you may use a simple file storage (in iOS you can use a NSKeyedArchiver to quickly build objects into a file format and NSKeyedUnarchiver to build objects from a file), or if you need more complex data relationships you would use a SQLite database on the device. On iOS you should use Core Data to manage the SQLite store for you.
You are correct. To get data from an external database you will need to make a webservice call To a script that returns the data you wish to use.
You can get the data back in JSON or XML format. I prefer JSON as I think it is easier and simpler.
AJAX would be a good way to make calls for your data.
Its a good idea to make a mix of both. You can use and webserver to store all your data but if the user is in an area that they can't use data then it would render your app useless. Normally I keep all the data I need on a server then download and store it in the apps DB for that user. You can then make a request to the server at intervals to see if there is any new data to be downloaded. I would suggest doing a similar thing for the bootstrap site.

Use protobuf on android to send data to WCF Service (using protobuf.net)

I need to send a object containing 256kb to 18Mb of data from an android device to a WCF service.
I just found out about protobuf.net and agree this is the way to go.
Most examples I find showing use of protobuf on android are designed to make queries like:
www.webservice.com/API/MaxItems=10.
What I need is a way to sent entire BLOBs to my webservice, not just parameters.
Can anyone point me in the right direction for coding this using android 2.3.3 and WCF.Net?
My scenario is as follows:
Webservice is serving clients using .Net and Silverlight and also clients on the android platform.
Webservice will serve data from filesystem and SQL to clients using protobuf.
Data beeing served will contain basic types and smaller binary chunks. 4-50Kb as protobuf objects.
There will be 17 functions taking parameters of basic types and 6 functions taking protobuf objects as parameters. One of the functions will take a protobuf object having 4 byte[] summing up to a maximum of 18Mb.
The characteristics of the served data makes protobuf a perfect match.
One of the requirements on the WebService API is to hold all these functions in one interface.
Personally, I think your best bet in that scenario (with android etc) would be to use regular in-memory serialization to create a BLOB, and then use whatever tools are available (http-post, WSE, sockets, whatever) to send that BLOB, and deserialize at the other end. Getting WCF to own the serialize/deserialize is a huge pain, especially if you aren't using full .NET. This approach should also make it pretty easy to switch between transport types entirely if needed, as you aren't really asking WCF to do much.

webservice on android with ksoap2 too slow

I have an android application acessing an webservice that returns a big result.
The return type, on the webservice C# server, is the type XmlElement.
My problem is, when I call it using ksoap2 on the android app, it takes a lot of time to process the result.
As the result is a xml, how can I force the ksoap to give me an String result without process it into a SoapObject?
Or there is another way to process the result more quickly?
Thanks and sorry for my bad english
I guess http get or post and sax xml parser can be used without soap. You will get faster response, smaller app size.
You need to run it in an async task and break it down to ensure the result xml is not too big. The WSDL does not matter since it is not used.
In terms of processing the xml with something else rather than using the parsed SoapObject tree:
If you do that you might as well not use KSAOP2. And you probably wont find anything faster either since KSOAP2 is already very lightweight and fast. You just use a different stack to do the same thing.

Android webservice practice?

I currently have a database and want my android apps to access a webservice and then access the database.
Currently i'm thinking of using either option. ksoap with asp.net that uses .asmx files created and also a page using asp.net that response.write json output. May i know which should be the better choice?
I would go the JSON route. Android has an API for parsing JSON built-in, and JSON format is more efficient in terms of size.
Aside from basic XML parsers, there's nothing built into android to handle SOAP, and from what I've seen, 3rd party offerings are limited.
Try this.The service is in php but should be simple to adapt ti asp.net.
http://www.embarcadero.com/rad-in-action/php-android

OutOfMemoryException in kSOAP

I am sending multiple PDF files through SOAP which will be received by an Android client. But when receiving the SOAP response, it is throwing OutOfMemoryException.
I want to know whether its a limitation of kSOAP or Android. Please guide me how to overcome it.
Thanks.
I would suggest to not do that. Just put the raw url to the pdf file into the soap message and download the pdf separately independent of soap. That works great for me with PDF files as well as images..
So in a bit more detail:
One of your results from the SOAP request should contain a full public url to the PDF file somewhere on the internet.
Then use DownloadManager or whatever you want in terms of Android development to get the file downloaded by using the url you got from the soap response. But dont have the PDF wrapped within the soap request. That way you can also show a progress bar during download and so on nicely. Downloading files on Android is documented everywhere..
I now that this is old question but maybe I help other developers. The most efficient way to sending a large binary content from/to web service is MTOM transfer (SOAP with attachments). The problem is that ksoap2 library doesn't support this feature, but you can try http://easywsdl.com generator. What I know is that it supports MTOM transfer and allows you to send/retrieve very large binary files. Of course MTOM transfer has to be enabled also on the web service side.

Categories

Resources