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
}
Related
I created Java web services and trying to connect with android code.I am getting the service running but android app is showing error in soap object creating for namespace and method name.I did all the changes and everything is correct namespace,method name,URL all is correct.But I don't know what is wrong can anyone help me out...!
My android code is----->
showing error in
-"SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);"
public class RetailerActivity extends Activity {
private static final String SOAP_ACTION = "urn:training/searchCompanyInfo";
private static final String METHOD_NAME = "searchCompanyInfo";
private static final String NAMESPACE = "urn:training/";
private static final String URL = "http://localhost/attest/CompanyInfoService?wsdl";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println(NAMESPACE);
System.out.println(METHOD_NAME);
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 = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}
}
In Android, You cannot perform network operation on the main thread, You need to execute your soap request in a background thread. Please read up on AsyncTask.
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());
}
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 have a wsdl file it the website and i would like to get some services.
My question is: how to find those parameters:
SOAP_ACTION
METHOD_NAME
NAMESPACE
URL
Here is my code but I have the connexion problem:
public class TestBookSoapActivity extends Activity {
private static final String SOAP_ACTION = "http://api.mdpi.com/ws/GetVersionInfo";
private static final String METHOD_NAME = "GetVersionInfo";
private static final String NAMESPACE = "http://api.mdpi.com/ws/";
private static final String URL = "http://api.mdpi.com/ws/mdpi.wsdl";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
executeAppelSOAP();
}
private void executeAppelSOAP() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0", "10");
SoapSerializationEnvelope enveloppe = new SoapSerializationEnvelope(SoapEnvelope.VER11);
enveloppe.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);
try {
androidHttpTransport.call(SOAP_ACTION, enveloppe);
Object resultat = enveloppe.getResponse();
System.out.println("Version = " + resultat.toString());
} catch(Exception e) {
e.printStackTrace();
System.out.println("Problem");
}
}
}
Use Soap-Ui http://www.soapui.org/ to get answers to your problem. Then modify your android code accordingly...
I get the wsdl and the URL,and the server is written in C++;
I use KSoap2 in android to access the method ,but it always
prints out :"Method 'methodname' not implemented"!!!
Can anyone help me out?
Thanks in advance!
Are you creating your request and the SoapAction properly?
Try the example below (it is a public web service with 0 arguments) and see if it works for you.
private static final String WSDL_URL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL";
private static final String WS_NAMESPACE = "http://ws.cdyne.com/WeatherWS/";
private static final String WS_METHOD_NAME = "GetWeatherInformation";
// 1. Creating SOAP request with no arguments
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(new SoapObject(WS_NAMESPACE, WS_METHOD_NAME));
// 2. Create a HTTP Transport object to send the web service request
HttpTransportSE httpTransport = new HttpTransportSE(WSDL_URL);
httpTransport.debug = true; // allows capture of raw request/respose in Logcat
// 3. Make the web service invocation
httpTransport.call(WS_NAMESPACE + WS_METHOD_NAME, envelope);
Log.d(TAG, "HTTP REQUEST:\n" + httpTransport.requestDump);
Log.d(TAG, "HTTP RESPONSE:\n" + httpTransport.responseDump);
Have a look at this detailed tutorial explaining the basics of using kSOAP2 with Android
see here the simple example of ksoap may help http://vimeo.com/9633556
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://216.128.29.26/webservices/TempConvert.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit"
you should specify necessary field as above.
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://216.128.29.26/webservices/TempConvert.asmx";
private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv;
tv = (TextView) findViewById(R.id.tv);
tv.setText(ws());
}
public String ws() {
String result = "";
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Celsius", "32");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
if(envelope.getResponse()!=null){
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
result = "FeranHit : " + response.toString();
}
}
catch (Exception e)
{
result = e.getMessage();
}
return result;
}
see this is my code. and m getting full result. This is just test program for ksoap2.
i have not included any libraries here.