您好我正在尝试通过以下链接连接网络服务的Android应用程序
我可以在Web服务中创建xsdl文件 这是android
中的代码package com.example.androidwsdlfrontend;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidWSDLFrontEnd extends Activity {
private String METHOD_NAME = "sum"; // our webservice method name
private String NAMESPACE = "http://calculator.backend.web.org";//”"; // Here package name in webservice with reverse order.;
private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name
private static final String URL = "http://10.0.2.2:8080/AndroidBackend/services/Calculate?wsdl";//”"; // you
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_wsdlfront_end);
TextView tv = (TextView) findViewById(R.id.txtAddition);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("i", 5);
request.addProperty("j", 15);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
System.out.println("Result: " + result.toString());
((TextView) findViewById(R.id.txtAddition)).setText("Addition: "+ result.toString());
} catch (Exception E) {
E.printStackTrace();
((TextView) findViewById(R.id.txtAddition)).setText("Error: "+ E.getClass().getName() + ":" + E.getMessage());
}
}
}
在我编译时的上述代码中,我收到错误
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
但我不知道如何解决它。请帮我。 我在那个特定位置提到了我的ipaddress。
答案 0 :(得分:1)
以下视频教程可能有所帮助: https://www.youtube.com/watch?v=v9EowBVgwSo https://www.youtube.com/watch?v=t8__EuSS69E
不要忘记添加访问互联网的权限
检查参数情况是否与中的相同 网络服务