从android调用.net web服务无法正常工作

时间:2011-01-13 14:02:33

标签: .net android web-services

我从我的Android应用程序调用.net Web服务没有运气。 这是我的代码:

package com.reza;

import android.app.Activity; import android.os.Bundle; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.widget.TextView;

public class callWebservice extends Activity {      private static final String METHOD_NAME =“HelloWorld”;

 private static final String NAMESPACE = "http://tempuri.org/";
 private static final String URL = "http://service.screwedmind.com/LocalBusiness.asmx";
 private static final String SOAP_ACTION = null;
 TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv=(TextView)findViewById(R.id.text1);
    call();
}
public void call()
{
        try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

        String result=(String)envelope.getResponse();

        tv.setText(result);
        } 
        catch (Exception e) {
            tv.setText("error occured..");
        }
}

}

当我运行这个程序时,我看到我的错误文本是“出错”... 任何人都可以指导我做错了什么。

3 个答案:

答案 0 :(得分:0)

“错误发生..”是您的错误消息,写下tv.setText(e.toString());,您在那里看到了什么消息?

答案 1 :(得分:0)

您可能只需要设置SOAP_ACTION = NAMESPACE + METHOD_NAME

答案 2 :(得分:0)

您应该更改SOAP_ACTION = NAMESPACE + METHOD_NAME