开发者

Getting Started with KSOAP on Android

i am trying to create web service call in Visual Studio 2008. But while running android application i am not getting any output in emulator. can you please tell me whats the problems in my coding so that i can fix it.

_

Public Function HelloWorld() As String 
Return "Hello how are you"
End Function

similarly in .java file of android i have used codings as:

package com.webservicetest;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;


public class webservicetest extends Activity {
private static final String NAMESPACE = "http://localhost/webservicetest/" ;
private static final String URL = "http://192.168.1.10/webservicetest/Service.asmx";
private static final String HelloWorld_SOAP_ACTION = "http://localhost/webservicetest/HelloWorld";
private static final String METHOD_NAME1 = "HelloWorld";

public static void main(String[] args)
{
Get开发者_JAVA技巧HelloWorld();
}
/** Called when the activity is first created. */
public static void GetHelloWorld() {

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
//SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);


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

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{

androidHttpTransport.call(HelloWorld_SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
int result = Integer.parseInt(response.getProperty(0).toString());




}
catch(Exception e)
{   
e.printStackTrace();

}

}
}

i am getting error in int result = Integer.parseInt(response.getProperty(0).toString()); as "The local variable result is never read".


The error you point out is not what makes your app not running, it only says that you're using a variable but never read it. In Android development you don't use main() method, but mostly you override Activity.onCreate().

Here you find some tutorials.

(the GetHelloWorld() method seems ok)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜