http://i.stack.imgur.com/pK9rm.png
http://i.stack.imgur.com/27Qj0.png
I want to connection web service using ksoap2,I have a working example but how can I integrate my application?
public class WebServiceDemoActivity extends Activity
{
private static String SOAP_ACTION = "http://tempuri.org/UrunleriListele";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "UrunleriListele";
private static String URL = "http://services.annebebekavm.com/Service1.asmx?WSDL";
Button btnFar,btnCel,btnClear;
EditText txtFar,txtCel;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFar = (Button)findViewById(R.id.btnFar);
txtFar = (EditText)findViewById(R.id.txtFar);
btnFar.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Fahrenheit",txtFar.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
txtFar.setText(result.getProperty(0).toString());
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Please reconsider to use another client
http://code.google.com/p/android-ws-client/
you can create all classe what you need to.
by one application copy libs to your project
with your generate classes
Here is example it look really simple to
Service servis = new Service();
ServiceSoap soap12 = servis.getServiceSoap12();
LoginParams inParams = new LoginParams();
inParams.setLogin("user");
inParams.setPassword("pass");
inParams.setStrategy(LoginStrategy.NOHASHPASS); // even enums are supported
LoginState result = soap.authorize(inParams);
result.isLogin(); // boolean if is succesfull
Related
I have connected to the asp.net Service using Ksoap2 and it connects fine, but one thing is that i get the response back in XML. Is there anyway i can get it to display in normal text.
This is the code i have used
public class AndroidWebService extends Activity {
/** Called when the activity is first created. */
private static String SOAP_ACTION = "http://tempuri.org/GetHelpDeskCalls";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "GetHelpDeskCalls";
static final String URL = "https://198.125.364:8080/AndroidServices/Service1.asmx";
Button getData;
EditText userID;
TextView data;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.helpdesk);
getData = (Button) findViewById(R.id.button1);
userID = (EditText) findViewById(R.id.txtFar);
data = (TextView) findViewById(R.id.textView1);
Thread nT = new Thread() {
#Override
public void run() {
getData.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
request.addProperty("userID", userID.getText()
.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
// androidHttpTransport.call(SOAP_ACTION, envelope);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
final String ss = androidHttpTransport.responseDump;
// final SoapObject response = (SoapObject) envelope
// .getResponse();
runOnUiThread(new Runnable() {
public void run() {
data.setText(ss.toString());
}
});
} catch (Exception e) {
data.setText("Error");
}
}
});
}
};
nT.start();
}
}
There is a neat website called google, it does wonders.
since you seem to be lazy there are 3 basic xml parsing methods you can use
SAX parser,
DOM parser,
XML pull parser
read about xml parsing here
Could anyone please help in processing the SOAP request and response from an android application.
I have followed the tutorial at
http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/
But when I run the application, it exits prematurely with the error
Unfortunately, has stopped.
I am running it in an emulator.
Can anyone please explain what I might be missing. Any example source code will be very useful.
I have one simple code for you. Where we have a button and we will be calling helloworld method.
Button Worldmethod;
private static final String SOAP_ACTION1 = "http://tempuri.org/HelloWorld";
private static final String HelloWorldmethod = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.5/MobileDemo/Demo.asmx";
#Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.webservices_layout);
Worldmethod= (Button)findViewById(R.id.Worldmethod);
Worldmethod.setOnClickListener(this);
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.Worldmethod:
try
{
methodbody= (TextView)findViewById(R.id.methodbody);
SoapObject request1 = new SoapObject(NAMESPACE, HelloWorldmethod);
// add paramaters and values
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request1);
//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION1, envelope);
//get the response
SoapPrimitive result= (SoapPrimitive)envelope.getResponse();
String results = result.toString();
methodbody.setText( ""+results);
}
catch (Exception e)
{
methodbody.setText(e.getMessage());
e.printStackTrace();
}
break;
}
}
The above image is just adding two values and displaying the result on the below textview.
But i need to show that answer on the first tab(ie.Tab_1) of tabhost on next screen.
How to do this?
.java class
public class Demo_webserviceActivity extends Activity
{
/** Called when the activity is first created. */
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "FahrenheitToCelsius";
private static String SOAP_ACTION = "http://tempuri.org/FahrenheitToCelsius";
private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
Button btnFar;
EditText txtFar;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFar = (Button)findViewById(R.id.btnFar);
txtFar = (EditText)findViewById(R.id.txtFar);
btnFar.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String b;
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Use this to add parameters
request.addProperty("Fahrenheit",txtFar.getText().toString());
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
if(result != null)
{
//Get the first property and change the label text
b = result.toString();
Intent i = new Intent(getApplicationContext(),Activity2.class);
i.putExtra("gotonextpage", b.toString());
startActivity(i);
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
}
NOTE : This source is actually consuming a webservice from android and showing the result by SOAP method
Thanks a lot.
You can use Shared preferences to store values, then you can access it in any activity of your project:
follow this link
I am using Soap WEb service but I am facing one problem like this soap:Server' faultstring: 'Server was unable to process request. ---> There is no row at position 0.' faultactor: 'null
My Code is
public class GetData extends Activity {
private static final String SOAP_ACTION="http://xxx.mobi/GetMobileContentMetaData";
private static final String METHOD_NAME="GetMobileContentMetaData";
private static final String NAMESPACE ="http://xxx.mobi/";
private static final String URL = "http://webservices.xxx.mobi/MobileLMSServices.asmx";
SoapObject request;
Button submit;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getdata);
submit=(Button)findViewById(R.id.submit);
submit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("SiteURL","http://heaklthcare.xxx.mobi/");
request.addProperty("ContentID","62b90739-57b9-47cc-884a-8be2ef265304");
request.addProperty("UserID",809);
request.addProperty("DelivoryMode",2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
SoapObject result = null;
envelope.setOutputSoapObject(request);
AndroidHttpTransport sab = new AndroidHttpTransport(URL);
sab.debug = true;
try {
sab.call(SOAP_ACTION, envelope);
if (envelope.getResponse() != null)
{
result = (SoapObject) envelope.bodyIn;
for (int i1 = 0; i1 < 1; i1++) {
Object property = result.getProperty(i1);
if (property instanceof SoapObject) {
SoapObject countryObj = (SoapObject) property;
Log.d("country" ,"object"+countryObj);
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Should be an error returned by the server. If you can, call the web method from .net (or if you have a localhost copy of the webservice, input parameters in the browser) .
I struggled with this error this morning, then I did a small (5 lines) .net app to call the web method. then i got a clearer error message. Also turned out my java code had no problems the whole time.
I want to use a SOAP-based web service in Android, but I don't know the concept of how to use SOAP-based web services. I previously have done XML parsing for simple XML web services, but don't know about SOAP-based ones. Can you tell me how to use SOAP-based web services in Android...
Try this, This code is for login-user using Ksoap
public class Login extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/LoginUser";
private static final String METHOD_NAME = "LoginUser";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://"
private static final String TAG = "HELLO"
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button signin = (Button) findViewById(R.id.regsubmitbtn);
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new StartLoginAsyncTask(yourclass.this).execute();
}
});
}
private class LoginTask extends AsyncTask<Void, Void, Boolean> {
private final ProgressDialog dialog =
new ProgressDialog(YourClass.this);
protected void onPreExecute() {
this.dialog.setMessage("Logging in.........");
this.dialog.show();
}
protected Boolean doInBackground(final Void unused) {
return Main.this.login(); //don't interact with the ui!
}
protected void onPostExecute(final Boolean result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (result.booleanValue()) {
//also show register success dialog
}
}
}
private String doLogin() {
EditText etxt_user = (EditText)findViewById(R.id.emaileditlog);
String email_id = etxt_user.getText().toString();
EditText etxt_password = (EditText)findViewById(R.id.pwdeditlog);
String password = etxt_password.getText().toString();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("email", email);
request.addProperty("password", password);
SoapSerializationEnvelope soapEnvelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
Pattern EMAIL_ADDRESS_PATTERN =
Pattern.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\#" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
")+");
Matcher matcher = EMAIL_ADDRESS_PATTERN.matcher(email_id);
if (matcher.matches()) {
Log.v(TAG, "Your email id is valid ="+email_id);
// System.out.println("Your email id is valid ="+email);
} else {
// System.out.println("enter valid email id");
Log.v(TAG, "enter valid email id" );
}
if (password != null) {
if (email_id.equalsIgnoreCase("") || password.equalsIgnoreCase("")) {
System.out.println("Fields should not be EMPTY");
}
}
SoapObject request = new SoapObject(NAMESPACE_LOGIN, METHOD_NAME_LOGIN);
request.addProperty("email", email_id);
request.addProperty("pwd", password);
SoapSerializationEnvelope soapEnvelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL_LOGIN);
try {
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
aht.call(SOAP_ACTION_LOGIN, soapEnvelope);
SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
Log.v("TAG", String.valueOf(resultsRequestSOAP));
Object response=(Object)soapEnvelope.getResponse();
temp=response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}
}
You should download and try out ksoap2 for Android.
You must do a thorugh research before asking a question. It is a simple problem which can be solved using google.
Anway, use these links
http://tknight.org/sdn/show/23160
http://www.android10.org/index.php/articleslibraries/167-using-ksoap2-for-android-soap-web-service
http://android.amberfog.com/?p=45
Also, use ksoap2 library from http://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.5.7/ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar. Click on view raw file to download the jar