Calling a webservice from Android app
There are two parts
Part 1: Creating a WSDL Service.
Part 2: Calling A WEB SERVICE from Android App.
——————————————————————————————————
——————————————————————————————————
- Prerequisite: Eclipse which supports web development.
- Download Axis2-1.4 from http://ws.apache.org/axis2/download/1_4/download.cgi
- Download the zip version of “Standard Binary Distribution”.
- Extract in the desired folder and keep a note of its location.
- Open Eclipse. Go to Window -> Preference and you will get the following screen
- Click on “Web Services -> Axis2 Preferences”
- Browse the directory to the location, where we have extracted The “axis2-1.4”
- We should get the following screen “Axis2 runtime loaded sucessfully”.
- Click “OK”
- Create a new “Dynamic Web Project”
- Make sure Server is configured Properly.
- Click Finish.
- Create a new package. Right Click on “src -> New -> Package “
- Click Finish.
- Create a new Java class inside the same Package.
- Click Finish.
- package org.web.backend.calculator;
- Create class “Calculate” inside the package, with following methods.
public int subtract(int i, int j) {public class Calculate {
public int sum(int i, int j) {
return (i + j);
}
return (i – j);
}public int multiply(int i, int j) {
return (i * j);
}public int divide(int i, int j) {
return (i / j);
}
} - Save the file.
- When services are deployed to Axis, the wsdd file is used during the deployment and its contents end up within server-config.wsdd in /usr/local/OMII/jakarta-tomcat-5.0.25/webapps/axis/WEB-INF.
- Since we dont have such file, we have to create a “server-config.wsdd”
- Right Click on “WEB-INF” and select “New -> File”. Name it as “server-config.wsdd”.
- The contents can copy pasted from this link
- Make sure you have the following jar files inside the library of created Project.
- activation.jar
- commons-discovery.jar
- jaxrpc.jar
- mail.jar
- saaj.jar
- These jar files are required for successful completeion of creation of WSDL service. So if you dont have kindly download it inside the lib folder of axis2-1.4, as shown below.
- So now we to copy paste all the library from bin folder inside the lib of project
- From : C:\Users\j3 d patel\jars\Axis2\axis2-1.4\lib
- To : WEB-INF\lib
- Now Project Explorer looks like the following screen shot
- Right Click the Java Class we created “Calculate.java”.
- New -> WebService.
- Click Next
- Click on Web Service runtime : Apache Axis
- Select Apache Axis 2 and click OK. Finally it should look like the foloowing screen shot.
- Select Next.
- Select Next and then click “Start Server.”
- Click “Next”
- Click Finish.
- Right click on Project. Select Run As -> Run on Server
- If you get the following error “HTTP Status 404 – /AndroidBackend/”……its fine. dont worry about it.
- Change the url to “http://localhost:8080/AndroidBackend/axis2-web/index.jsp”.
- If you get the following screen, everything is working fine.
- Click on Services.
- If you get the above screen, we have sucessfully created a wsdl file. The only step Remaining is to click on “Calculate”.
- If it points to “http://localhost:8080/AndroidBackend/services/Calculate?wsdl” with a wsdl file in your web browser, We have successfully created a wsdl file for our android app.
- Keep a note of this wsdl url as it will be required in Part 2.
Go to : Part 2 : For calling webservice from ANDROID
——————————————————–
For calling webservice from Flex application
<fx:Declarations>
<!– Place non-visual elements (e.g., services, value objects) here –>
<s:WebService id=”calculatorService”
wsdl=”http://localhost:8080/AndroidBackend/services/Calculate?wsdl”
result=”calculatorService_resultHandler(event)”
fault=”calculatorService_faultHandler(event)”/></fx:Declarations>
<s:Panel x=”75″ y=”87″ width=”312″ height=”260″ title=”Calculator”>
<s:Button id=”add” x=”15″ y=”163″ width=”53″ label=”+”
click=”calculatorService.sum(Number(number1.text),Number(number2.text));”/><s:Button id=”divide” x=”211″ y=”163″ width=”53″ label=”/”
click=”calculatorService.divide(Number(number1.text),Number(number2.text));”/><s:Button id=”multiply” x=”148″ y=”163″ width=”53″ label=”*”
click=”calculatorService.multiply(Number(number1.text),Number(number2.text));”/><s:Button id=”subtract” x=”81″ y=”163″ width=”53″ label=”-”
click=”calculatorService.subtract(Number(number1.text),Number(number2.text));”/>
Good work dude…really helpful
U can call SOAP web-services using a wrapper called K-SOAP.
Yes it is possible. You can refer the following blog.
http://blog.futurebytez.com/2010/05/web-services-in-android-using-ksoap2.html
Nice Article…Very HelpFull.
Nice link for complex data type wsdl.
1. http://www.javaranch.com/journal/200603/WSComplexTypes.html
SNIPPET : Calling webservice from flex application.
Hi there !
I would like to know how can I deploy the webservice on my remote server running on ubuntu.
Apache tomcat is already installed, but i don’t know i can put it on my remote server from eclipse.
Thanks.
Eric,
Option 1: Manually transfer .war file into webapps folder of Remote tomcat.
Option 2: Configure Eclipse. Hope this link helps (http://www.myeclipseide.com/documentation/quickstarts/remotedebugging/)/
All works fine upto https://jatin4rise.files.wordpress.com/2010/10/110.jpg for me.
But after Starting Tomcat server (Start server) ,when proceed to next eclipse became ‘Not responding’.
But my machine has Core I5 processor with 8 GB ram.Yet Can’t proceed.
Any help would be appreciated.
Its not related to blog. wish i could have helped u. 😦
Many thanks,,,,,it was so helpful for me….
Thanks in advanced….. 🙂
Hey good work.. helped me lot..
Can u please help me about this..
I have created one signup page in android and it contains some text boxes for names and also it contains one upload button throgh this ihave to upload image from android gallery and have to store it in mysql.
How can I store image into mysql using web services?
I appreciate your help..
Thanks in advance
Cool! Nice blog you have mate!
Keep running 🙂
—
devmain.blogspot.com
Thanks!
Really nice article itsvery useful blog jatin it worked for me but i need some help fro you would u contact me at balajikitit@gmail.com