我正在尝试在Visual Studio 2008中创建Web服务调用。但是在运行Android应用程序时,我没有在模拟器中获得任何输出。你可以告诉我我的编码中的问题是什么,以便我可以解决它。
_
Public Function HelloWorld() As String
Return "Hello how are you"
End Function
同样在android的.java文件中我使用了编码:
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)
{
GetHelloWorld();
}
/** 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();
}
}
}
我在int result = Integer.parseInt(response.getProperty(0).toString());
收到错误,因为“永远不会读取本地变量结果”。
答案 0 :(得分:0)
你指出的错误并不是你的应用程序没有运行的原因,它只是说你使用的是变量但从未读过它。在Android开发中,您不使用main()
方法,但主要是覆盖Activity.onCreate()
。
Here你找到了一些教程。
(GetHelloWorld()
方法似乎没问题)