this is my web service .i want to fetch only name . but when i am running my application i am getting an error.
java.lang.NoClassDefFoundError:org.ksoap2.serilization.soapobject at my package name
public static String SOAP_ACTION1 = "http://tempuri.org/GetContact";
// private static String SOAP_ACTION2 = "http://tempuri.org/CelsiusToFahrenheit";
public static String NAMESPACE = "http://tempuri.org/";
public static String METHOD_NAME1 = "GetContact";
//private static String METHOD_NAME2 = "CelsiusToFahrenheit";
private static String URL = "http://115.119.182.114/Rotaryclub/RotaryService.asmx";
TextView txt;
//ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.displaycontacts);
txt=(TextView) findViewById(R.id.textView11);
//CALL the web service method with the two parameters vname and nname
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
request.addProperty( "Cid","1");
request.addProperty("Position", "doctor");
request.addProperty("Name", "abhishek");
request.addProperty("ImageUrl", "test.jpg");
request.addProperty("PhoneNo", "4324434323");
request.addProperty("MobileNo", "4324434323");
request.addProperty("FaxNo", "43-434-34");
request.addProperty("EmailId", "abh22ishek#gmail.com");
request.addProperty("Address", "kalkere");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// Make the soap call.
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
// SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
// String strRes = result.toString();
if(result != null){
txt.setText("SOAP response:\n\n" + result.getProperty(2).toString());
}
Related
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/xxxx/GetLatLong";
private static final String METHOD_NAME = "GetLatLong";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://xxxx:xxxx/xxxx.svc/soap";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
}
catch (Exception exception)
{
textView.setText(exception.toString());
}
}
}
This is an example of my code.
This returns a string with 3 data description latitude and longitude .
I want to handle them separately how can I manage this ?
I want to put it then on a map with that configuration.
Write code something like this
JSONArray array=new JSONArray("your string response in json format");
for(int count=0;count<array.length();count++)
{
JSONObject obj=array.getJSONObject(count);
String description=obj.optString("Description");
String latitude=obj.optString("Latitude");
String longitude=obj.optString("Longitude");
// Logic to display latlong on map
}
class wsCall extends AsyncTask {
private static final String SOAP_ACTION = "http://tempuri.org/PrivateLogin";
private static final String METHOD_NAME = "PrivateLogin";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.110/omoffice/service/wsomjobs.asmx";
private Context mContext;
public wsCall (Context context){
mContext = context;
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
protected String doInBackground(String... params)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid","poma");
request.addProperty("pw","1");
request.addProperty("azienda","1");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.bodyIn;
return "OK";
In androidHttpTransport.call(SOAP_ACTION, envelope) I obtain this error: java.net.ProtocolException: unexpected end of stream
Someone help me?
thanks
Marco
Are you sure if SOAP version you are using is 10??
try using SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); instead of SoapObject response = (SoapObject) envelope.bodyIn;
Thanks in advance please forgive me if I am making any mistake while explaining the problem.
I am new TO SOAP technology. I want to call a WCF .net based SOAP web service the request for the SOAP will look something like below
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:IsServiceLive_V>
<!--Optional:-->
<tem:version>1</tem:version>
</tem:IsServiceLive_V>
</soapenv:Body>
</soapenv:Envelope>
and I am trying to make the request in the code like this
public class MainActivity extends Activity {
public static String SOAP_ACTION1="http://tempuri.org/IService1/IsServiceLive_V";
public static String SOAP_ACTION2="http://tempuri.org/IService1/IsServiceLive_V";
public static String METHOD_NAME1="IsServiceLive_V";
public static String METHOD_NAME2="IsServiceLive_V";
public static String NAMESPACE="http://tempuri.org/";
public static String URL="http://64.27.48.117:3340/service/Service1.svc?wsdl";
Button btnFar,btnCel,btnClear;
EditText txtFar,txtCel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFar = (Button)findViewById(R.id.btnFar);
btnCel = (Button)findViewById(R.id.btnCel);
btnClear = (Button)findViewById(R.id.btnClear);
txtFar = (EditText)findViewById(R.id.txtFar);
txtCel = (EditText)findViewById(R.id.txtCel);
btnFar.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
//Initialize soap request + add parameters
try
{
new SoapResult(1).execute();
}
catch(NullPointerException e)
{
}
}
});
}
public class SoapResult extends AsyncTask<Void, Void, SoapObject>
{
int flag_status;
SoapObject final_result;
public SoapResult(int flag) {
// TODO Auto-generated constructor stub
flag_status=flag;
}
#Override
protected SoapObject doInBackground(Void... arg0) {
// TODO Auto-generated method stub
if(flag_status==1)
{
//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
//Use this to add parameters
/* PropertyInfo property=new PropertyInfo();
property.setName("tmp");
property.setValue("GetRestaurantList");
request.addProperty(property);*/
request.addProperty("version", "1");
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
System.out.println(request.toString());
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION1, envelope);
System.out.println("ok");
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
System.out.println(result.toString());
//SoapResult soap=(SoapResult)envelope.getResponse();
//Get the first property and change the label text
final_result=result;
} catch (Exception e) {
e.printStackTrace();
System.out.println("hiiii...");
}
return final_result;
}
#Override
protected void onPostExecute(SoapObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if(flag_status==1)
//txtCel.setText(result.getProperty(0).toString());
if(flag_status==0)
{
// txtFar.setText(result.getProperty(0).toString());
}
}
}
and the SOAP response in SOAP format should look something like this
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<IsServiceLive_VResponse xmlns="http://tempuri.org/">
<IsServiceLive_VResult>true</IsServiceLive_VResult>
</IsServiceLive_VResponse>
</s:Body>
</s:Envelope>
but it is giving me exception java.lang.IllegalArgumentException: size <= 0
after the call
androidHttpTransport.call(SOAP_ACTION1, envelope);
The XML SOAP request and responses are generated using Soup UI tool and are working fine
just not getting where i am going wrong a little bit help would be appreciable..
Once I was having the same issue. There might be some problem with your service.
And use this
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
Instead of
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Got the answer for what i was looking for . for the WCF web services we have to create separate class for each method to get the data since it cannot be run from the code where you wanted the results . So if anyone has the problem that I faced please do remember that to consume the WCF web service in your android project Create a different class for each method for the web service .I am giving an simple example below
public class GetNearBy {
public static String HOTEL_NAME="hotel_name";
public static String NUMBER_OF_BRANCHES="branches";
public static String IMAGE1="image1";
public static String IMAGE2="image2";
public static String IMAGE3="image3";
public static String IMAGE4="image4";
public static String IMAGE5="image5";
public static String IMAGE6="image6";
public static String HAS_EVENT="HasEvent";
public static String HAS_OFFER="HasOffer";
public static String HAS_MENU="HasMenu";
public static String HAS_POPULARFOOD="HasPopularFood";
public static String ID="Id";
public static String IS_OPEN="IsOpen";
public static String LAT="LAT";
public static String LONG="LONG";
public static String LOCATION="Location";
public static String STARS="Stars";
public static String FACILITY_COUNT="facility_count";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "GetNearBy";
private static final String SOAP_ACTION = "http://tempuri.org/IService1/GetNearBy";
private static final String URL = "http://xxxxxx/service/Service1.svc/soap";
public static ArrayList<HashMap<String, String>> connectToSOAPService()
{
ArrayList<HashMap<String, String>> data=new ArrayList<HashMap<String,String>>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// creating SOAP envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// this should be true even in not .NET services
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String resultValue = "";
try {
// calling an action
androidHttpTransport.call(SOAP_ACTION, envelope);
// receiving response
SoapObject response = (SoapObject) envelope.getResponse();
for(int i=0;i<response.getPropertyCount();i++)
{
HashMap<String, String> result=new HashMap<String, String>();
SoapObject ele1=(SoapObject)response.getProperty(i);
String Hotel_name=ele1.getProperty("BranchName").toString();
result.put(HOTEL_NAME, Hotel_name);
data.add(result);
}
}
catch(Exception e)
{
}
return data;
}
}
and just call it from where you need to fetch the result from the WCF web service like this
GetNearBy.connectToSOAPService();
try like this
final String NAMESPACE = con.getResources().getString(
R.string.NAMESPACE);
final String METHOD_NAME = "ItemsByCountry";
final String SOAP_ACTION = con.getResources().getString(
R.string.SOAP_ACTION)
+ METHOD_NAME;
final String URL = con.getResources().getString(R.string.URL);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("userId", UserId);
Request.addProperty("countryName", countryName);
SoapSerializationEnvelope soapEnvelop;
soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
HttpTransportSE htp = new HttpTransportSE(URL);
htp.call(SOAP_ACTION, soapEnvelop);
response = (SoapObject) soapEnvelop.getResponse();
i have to use 2 soap call url is use in one class.
my code is:
public class Orderinfo extends Activity {
private static final String SOAP_ACTION = "http://xcart.com/data";
private static final String METHOD_NAME = "data";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8085/XcartLogin/services/RetailerWs?wsdl";
private static final String URL1 = "http://192.168.1.168:8085/XcartLogin/services/TodayC?wsdl";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = (TextView) findViewById(R.id.textView44);
// TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
} catch (Exception e) {
e.printStackTrace();
}
HttpTransportSE ht1 = new HttpTransportSE(URL1);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = (TextView) findViewById(R.id.textView43);
// TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here have to display first soap call output is 3.the second soap call output is 2.but both are displayed 2 only.why what exception is here.please help me.
you have used one evelope for request in both calls, so called service method and params are the same
I am trying to call a web service from Android client using the ksoap library.
Here is my android code
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx";
TextView tv;
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("name", "zawoad");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
String result = (String)envelope.getResponse();
tv.setText(result);
} catch (Exception e) {
tv.setText("exception :" + e.getLocalizedMessage());
}
}
And here is my web service method which is written in Test.asmx file
[WebMethod]
public string HelloWorld(string name)
{
return "Hello World" + name;
}
When the androidHttpTransport.call(SOAP_ACTION, envelope); line is executed it throws the following exception
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG #2:44 in java.io.InputStreamReader#43e593c8)
Please help..
This is working code
private static final String SOAP_ACTION = "http://tempuri.org";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx?wsdl";
/*write ?wsdl only for local system testing*/
TextView tv;
public void call()
{
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("name", "zawoad");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,20000);//Updated
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
String result = resultsRequestSOAP.toString();
tv.setText(result);
} catch (Exception e) {
tv.setText("exception :" + e.getLocalizedMessage());
}
}
The calling that you are performing will not happen.
what is the web service return type? We can pass the values and call that.