Android Tutorial ASMX Soap call,automatic call,response,parse and redirect to activity/service.

quaker

Member
Licensed User
Good Afternoon!

With a bit of work and thanks to this post:

http://www.b4x.com/android/forum/threads/b4a-tutorial-como-consumir-webservice-tipo-asp-net-asmx.45107/#content.


And thanks specially to XICU for helping with the code in my first investigations.

I have made an automated service,this service will automatically:

-Call a asmx .NET webservice method,authenticated or not, without need to build or cocatenate a string to build the POST request(i have done it for you :) inside the service).

-Protected for exceptions thrown by .NET webservice or errors on method calls.


-Its ready for recieving from webservice:

*Primitive types(string,int...etc)
*Complex Types(Object models,either one or list of them)

-Doesnt need to do XML SAX parse.It parses reading line by line automatically. :D

-Doesnt need external libraries.Only httputils2 and HTTP.


-All code is commented inside it for you to know whats happening in almost each line.

-If an object is returned from webservice,a list of objects,with a list of parameters(with key and value) in each object is returned.(In following weeks i will make an update,for parse those list of list to a android model we will prepare)


I attach 1 sample with 2 proyects:

-The B4A project sample(with webservicecall class,webservice service,and keyvaluepair class).This are the only three classes for SOAP to work as i explain.

-The .NET webservice asmx i used for example.Its done in VS2012.Only for tests.(You will have yours).You have to know how to include it to IIS,as i wont explain it here.

Things you will need to change for you to work with your webservice:

-In Webservice service,on top.The username,the password and the URL.Username and password only if authenticated,if not leave at it is.

-Put the asmx and the dll in IIS(or yours if you got one alredy) and configure it.Search Google if you dont know how to do it.

-In the main(from the b4a test sample,if want to test).Change(explained in main allredy):

*The Webservice asmx path to whatever you have put it, or yours is.
*The method you want to call.
*The parameters for that method.
*The object to search from asmx on response(if the method responses an object,not a primitive type)
*The response callback method in the activity or service if call to asmx has been called ok.
*The response callback method if the activity or service if call to asmx has errors.

This is it,if you got any questions,feel free to ask!.

:D.
 

Attachments

Top