首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用KSOAP2从安卓调用.NET Webservice?

如何使用KSOAP2从安卓调用.NET Webservice?
EN

Stack Overflow用户
提问于 2009-06-27 07:23:05
回答 5查看 126.8K关注 0票数 50

我在调用while服务时遇到问题。我在服务器上有一个完整的web服务,并且我在.NET中使用KSOAP2 (ksoap2-j2se-full-2.1.2)。在运行该程序时,我得到了一个运行时异常,如"org.ksoap2.serialization.SoapPrimitive“。我该怎么办?

这是我的代码。

package projects.ksoap2sample;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.*;
import android.os.*;
import android.widget.TextView;

public class ksoap2sample extends Activity {
    /** Called when the activity is first created. */
    private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
    private static final String METHOD_NAME = "HelloWorld";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://192.168.1.19/TestWeb/WebService.asmx";
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.text1);

        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            //request.addProperty("prop1", "myprop");

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

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.call(SOAP_ACTION, envelope);

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

            String[] results = (String[])  result;
            tv.setText( ""+results[0]);
        }
        catch (Exception e) {
            tv.setText(e.getMessage());
        }
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1052300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档