4
Answers

SOAP Webservices

Mushtaq Ali

Mushtaq Ali

8y
331
1
I am using Soap Webservices. I am a fresh learner and tried to write a code for SOAP Webservice. A very common example widely used on internet for practice " Celcius to Fehrenheit" and Fehrenheitto Celcius".  I am going to attach the code below. The same codes work perfectly in Eclipse while in android studio / Intellij it does not work. why? 
 
 
package com.example.user.soap_offloading;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private static String SOAP_ACTION1="http://www.w3schools.com/xml/CelsiusToFahrenheit";
private static String SOAP_ACTION2="http://www.w3schools.com/xml/FahrenheitToCelsius";
private static String NAME_SPACE="http://www.w3schools.com/xml/";
private static String METHOD_NAME1="CelsiusToFahrenheit";
private static String METHOD_NAME2="FahrenheitToCelsius";
private static String URL="http://www.w3schools.com/xml/tempconvert.asmx";

Button enter, enter1;
TextView tv1, tv2, tv3;
EditText et1, et2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clr=(Button)findViewById(R.id.button2);
enter=(Button)findViewById(R.id.button);
tv1=(TextView)findViewById(R.id.textView);
tv2=(TextView)findViewById(R.id.textView2);
tv3=(TextView)findViewById(R.id.textView3);
et1=(EditText)findViewById(R.id.editText);
et2=(EditText)findViewById(R.id.editText2);

enter.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View view) {
 
 SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME1);

//Use this to add parameters
request.addProperty("Fahrenheit",et1.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_ACTION1, envelope);

// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;

if(result != null)
{
//Get the first property and change the label text
et2.setText(result.getProperty(0).toString());
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});




enter1.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View view) {
 SoapObject request = new SoapObject(NAME_SPACE, METHOD_NAME1);

//Use this to add parameters
request.addProperty("Fahrenheit",et2.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_ACTION1, envelope);

// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;

if(result != null)
{
//Get the first property and change the label text
et1.setText(result.getProperty(0).toString());
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});



clr.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
et1.setText("");
et2.setText("");
}
});
}
}
Answers (4)
0
Afzaal Ahmad Zeeshan

Afzaal Ahmad Zeeshan

NA 36k 2m 8y
Ok, that can be some sort of deployment error. Can you check against the emulator's console and see if it shows any logs?
Accepted
0
Mushtaq Ali

Mushtaq Ali

NA 5 338 8y
Dear Afzaal .. Im already checked and did not find any error. Can you do a favor to me. Just come on skype or teamviewer and see my coding. If you find a solution. I will be waiting for your reply. Thanks
0
Mushtaq Ali

Mushtaq Ali

NA 5 338 8y
@ Afzaal Ahmad Zeeshan. Brother , the problem is there is no any error. I can run it but nothing happens when i run. There is no result and yeah I have already downloaded all the packages which are required by android studio. I have already worked in android studio and Intellij. They working perfect in my other packages. For this particular package it do not work.
0
Afzaal Ahmad Zeeshan

Afzaal Ahmad Zeeshan

NA 36k 2m 8y
Can you share the error?

I think the error is something with the code not being available. Android Studio requires you to re-download everything. You have to re-download the binaries and etc before you can program the application. Go to, Android SDK, and download the SDK packages that you require to build the application. Then try again.