SoapAction和Web服务不起作用

时间:2012-01-15 22:19:26

标签: android web-services soap httprequest

大家好,我正在做一个应用程序,我需要一些来自Web服务的信息,我写了这段代码:

package messinaline.matteo.app;

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 MessinaAppActivity extends Activity {
private static final String SOAP_ACTION = "FINDPORT";
private static final String METHOD_NAME = "FINDPORTRequest";
private static final String NAMESPACE = "urn:DefaultNamespace";
private static final String URL = "http://apps.messinaline.it:80/TestWSDL.nsf/CheckNaveNew?OpenWebService";
private Object resultRequestSOAP = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv = (TextView) findViewById(R.id.webservice);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    // SoapObject
    request.addProperty("SHIP", "Jolly Blu");
    request.addProperty("XDATE", "15/01/2012");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        String[] resultsRequestSOAP = (String[]) envelope.getResponse();
        tv.setText(resultsRequestSOAP[0]);
    } catch (Exception aE) {
        aE.printStackTrace();
        tv.setText("don't work");
    }
}
}

我在这里找到了这段代码http://www.anddev.org/calling_a_web_service_from_android-t348.html TextView告诉我“不工作”?为什么?谢谢你太多了

1 个答案:

答案 0 :(得分:0)

以防万一:不要忘记将其添加到您的清单中。

<uses-permission xmlns:android="http://schemas.android.com/apk/res/android" android:name="android.permission.INTERNET"></uses-permission>