I have .net Web Service and I want to use it on android. This web service's methods return List(Of String) and I didn't get response on android. What can I do ? Here is the code..
I'm working on it for 3 days and I didn't find any solution yet.
In short, I need some list from .net web service and add this list's items to spinner. Please help me.
public class MainActivity extends Activity {
private Spinner myspinner;
private static final String METHOD_NAME = "Sektorler";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/Sektorler";
private static final String URL = "http://www.xxxxxxxxxx.com/webservice1.asmx";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myspinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_main , SektorDoldur());
myspinner.setAdapter(adapter);
}
private ArrayList<String> SektorDoldur() {
ArrayList<String> sektorler = new ArrayList<String>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
if (response.hasProperty("String")) {
if (response.getPropertyAsString("String") == null) {
//do something
} else {
for(int i=0;i<response.getPropertyCount();i++){
// sektorler.add(i, response.getPropertyAsString("String"));
sektorler.add(response.getPropertyAsString(i));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sektorler;
}
Also I'm trying this code but it doesn't work.
public class MainActivity extends Activity {
private Spinner myspinner;
private static final String METHOD_NAME = "Sektorler";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/Sektorler";
private static final String URL = "http://www.xxxxxxxx.com/webservice1.asmx";
private String[] denemeList;
private String[] SektorDoldur(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.bodyIn;
denemeList = new String[response.getPropertyCount()];
for(int i=0;i<response.getPropertyCount();i++){
denemeList[i] = response.getPropertyAsString(i).toString();
}
}
catch (Exception e) {
e.printStackTrace();
}
return denemeList;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SektorDoldur();
myspinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_main , denemeList);
myspinner.setAdapter(adapter);
}
I got it !!
this is false;
SoapObject response = (SoapObject) envelope.bodyIn;
Lets see this code, it's true;
SoapObject response = (SoapObject) envelope.getResponse();
Finally there are some trick about it.
First of all delete ksoap2 jar file from your project.
Save it and close Eclipse.
Then copy ksoap2 jar file, go to your workspace folder.
Open your project folder, click "libs" folder and paste it.
Open again Eclipse and Run Project!!
private Spinner myspinner;
private static final String METHOD_NAME = "Sektorler";
private static final String NAMESPACE = "http://tempuri.org";
private static final String SOAP_ACTION = "http://tempuri.org/Sektorler";
private static final String URL = "http://www.xxxxxxxxxx.com/webservice1.asmx";
private String[] denemeList;
private void SektorDoldur(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
denemeList = new String[response.getPropertyCount()];
for(int i=0;i<response.getPropertyCount();i++){
denemeList[i] = response.getPropertyAsString(i).toString();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SektorDoldur();
myspinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, denemeList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myspinner.setAdapter(adapter);
}
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
}
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
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
Hi friends
I am using ksoap2 in android can anybody tell how to pass parameter value to webservice in android
Thanks
public class AndroidClientService extends Activity {
private static final String SOAP_ACTION = "http://10.120.10.87:8080/TestService/services/TestService/saveServices";
private static final String OPERATION_NAME = "saveServices";
private static final String WSDL_TARGET_NAMESPACE = "http://10.120.10.87:8080/TestService/services/TestService?WSDL";
private static final String SOAP_ADDRESS = "http://10.120.10.87:8080/TestService/services/TestService";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
setContentView(textView);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
/*
* PropertyInfo pi = new PropertyInfo(); pi.setName("celcius"); pi.type
* = PropertyInfo.OBJECT_CLASS; pi.setValue(100);
* request.addProperty(pi);
*/
request.addProperty("number", "8806007");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
textView.setText(response.toString());
}
catch (Exception exception)
{
textView.setText(exception.toString());
}
}
}
Refer : WEBSERVICE