I am trying to call an asp.net web service hosted on our local network
from android.
The ip address and port of where the web service can be located is on
12.102.122.137:5011. The name of the Web Service Is
AppWebService.asmx. The Web Method is called AuthenticateUser and
accepts 2 parameters of UserName and Password. It returns XML file
with some user information such as first name and last name.
I have read dozens of post trying to get this to work and am still
having issues. I have android 2.1 platform with the update to google
maps 4.2. I also downloaded the KSoap2 file ksoap2-j2me-
core-2.1.2.jar. Below is the code I have so far that I thought might
work. Can anyone let me know where I am going wrong?
package com.paad.appmobile;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
import android.view.View.OnClickListener;
import org.ksoap2.*;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
public class appmobile extends Activity {
/** Called when the activity is first created. */
private Button loginButton;
private EditText userName;
private EditText password;
private TextView loginresults;
private static final String SOAP_ACTION = "http://12.102.122.137:5011/
AppWebService.asmx?op=AuthenticateUser";
private static final String METHOD_NAME = "AuthenticateUser";
private static final String NAMESPACE="http://12.102.122.137:5011/";
private static final String URL="http://12.102.122.137:5011/
AppWebService.asmx";
private Object resultRequestSOAP=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
setContentView(R.layout.login);
loginButton = (Button) findViewById(R.id.login);
loginButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
login();
}
});
}
public void login()
{
userName = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
loginresults = (TextView) findViewById(R.id.loginreults);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userName", userName.getText());
request.addProperty("password", password.getText());
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransport androidHttpTransport = new HttpTransport(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive resultString =
(SoapPrimitive)envelope.getResponse();
//resultRequestSOAP = envelope.getResponse();
//String[] results = (String[]) resultRequestSOAP;
loginresults.setText("Status:" + resultString);
}
catch (Exception ae)
{
ae.printStackTrace();
}
}
}
Any help would be massively appreciated. I just can't seem to get the
correct configuration for the thing to work.
Thank you in advance.
crusso
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en