• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android and ASMX Web Services

nick123

Lurker
I try to transfer data between android and asmx web service. But when i got first problem i try to write samples example, but I get error again. My goal is to send to web service some data, get xml,and than parse it in sqllite table. But for start any answer of web service wold be good.

Code that i use is:

package com.example.proba;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.h t t pTransportSE;
import org.xmlpull.v1.XmlSerializer;

import android.app.*;
import android.os.*;
import android.widget.TextView;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "h t t p://ws.cdyne.com/WeatherWS/GetCityForecastByZIP";

private static final String METHOD_NAME = "GetCityForecastByZIP";

private static final String NAMESPACE = "h t t p://ws.cdyne.com/WeatherWS/";
private static final String URL = "h t t p://wsf.cdyne.com/WeatherWS/Weather.asmx";


TextView tv;
StringBuilder sb;
private XmlSerializer writer;



@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
sb = new StringBuilder();
call();
tv.setText(sb.toString());
setContentView(tv);
}

public void call() {
try {

SoapObject request = new SoapObject("h t t p://ws.cdyne.com/WeatherWS/",
"GetCityForecastByZIP");

PropertyInfo property = new PropertyInfo();
property.setNamespace("h t t p://ws.cdyne.com/WeatherWS/"); // namespace to ensure that the element-name is prefixed with the namespace
property.setName("ZIP"); // name of the argument as per wsdl document
property.setValue("12345"); // value of the property
property.setType(String.class);

request.addProperty(property);



SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);


h t t pTransportSE androidh t t pTransport = new h t t pTransportSE(URL);
androidh t t pTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

//to get the data
String resultData = result.toString();
// 0 is the first object of data


sb.append(resultData + "\n");
} catch (Exception e) {
sb.append("Error:\n" + e.getMessage() + "\n");
}

}

}
I add
uses-permission android:name="android.permission.INTERNET"

in manifest file, and /ksoap2-android-assembly-2.4-jar-with-dependencies.jar in libs.

Later i was think to i need to go async.
and i wrote something like:

[HIGH]
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tv = new TextView(this);
sb = new StringBuilder();

tv.setText(sb.toString());
setContentView(tv);
new Dowork().execute();
}
public class Dowork extends AsyncTask<String,Object,Object>
{


@Override
protected void onCancelled(Object result)
{
super.onCancelled();
}
@Override
protected void onPostExecute(Object result)
{

Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_LONG).show();


}
@Override
protected Object doInBackground(String ...params)
{
try {

SoapObject request = new SoapObject("h t t p://ws.cdyne.com/WeatherWS/",
"GetCityForecastByZIP");

request.addProperty("ZIP", "12345");



SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.setOutputSoapObject(request);


h t t pTransportSE androidh t t pTransport = new h t t pTransportSE(URL);
androidh t t pTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

//to get the data
String resultData = result.toString();
// 0 is the first object of data


sb.append(resultData + "\n");
} catch (Exception e) {
sb.append("ss");
}
return sb;

}

}
[/HIGH]
I try to debug and problem is something with "androidh t t pTransport.call(SOAP_ACTION, envelope)"
Please help me, tnx
 
Back
Top Bottom