Here is what I did to make it work:
1. My Web Service that was built by Visual Studio 2008 and .Net 3.5.
The Web Service URL is:
http://www.cypresspoint.com/DroidServic ... rvice.asmx.
This address is live. Please try it in your browser.
2. To make my web site compatible with Android, I had to add:
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
.
.
.
To the Visual Studio 2008 WebConfig.xml file.
3. I have downloaded ksoap2-android from:
http://code.google.com/p/ksoap2-android/.
4. I installed the jar-file using the instructions at:
http://developer.android.com/guide/appe ... nallibrary.
My Android test code is:
Using java Syntax Highlighting
- package com.hedgetools.testwebservice;
- import org.ksoap2.SoapEnvelope;
- import org.ksoap2.serialization.SoapObject;
- import org.ksoap2.serialization.SoapPrimitive;
- import org.ksoap2.serialization.SoapSerializationEnvelope;
- import org.ksoap2.transport.AndroidHttpTransport;
- import android.app.*;
- import android.os.*;
- import android.widget.TextView;
- public class TestWebService extends Activity {
- private static final String SOAP_ACTION = "http://www.CypressPoint.com/DroidService/HelloWorld";
- private static final String METHOD_NAME = "HelloWorld";
- private static final String NAMESPACE = "http://www.CypressPoint.com/DroidService/";
- private static final String URL = "http://www.CypressPoint.com/DroidService/DroidWebService.asmx";
- // private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
- // private static final String METHOD_NAME = "CelsiusToFahrenheit";
- // private static final String NAMESPACE = "http://tempuri.org/";
- // private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
- TextView tv;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- tv = new TextView(this);
- this.setContentView(tv);
- try {
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- // request.addProperty("Celsius", "32");
- SoapSerializationEnvelope envelope =
- new SoapSerializationEnvelope(SoapEnvelope.VER11);
- envelope.dotNet = true;
- envelope.setOutputSoapObject(request);
- AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
- androidHttpTransport.call(SOAP_ACTION, envelope);
- SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
- String strResult = result.toString();
- tv.setText("Result: " + strResult);
- tv.invalidate();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Also, make sure that you add the line:
<uses-permission android:name="android.permission.INTERNET" />
to your AndroidManifest.xml file of your projest.
I first tested the code using the tempuri Web Service. It worked fine. I then commented out this code and inserted the code to access my test Web Server.
If you don’t enable HttpSoap in the in your Web Service (step 2) you will get a null pointer exception in the line:
SoapObject result = (SoapObject) envelope.getResponse();
Please excuse the formatting of this article... it is my first. I didn't know how to format the Java code.
I hope this will help fellow Droids.
Charles

