using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace test
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [SoapRpcService]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class hello : System.Web.Services.WebService
    {        [SoapRpcMethod, WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}web service  最基本的asp.net的web servicepackage org.stu;import java.io.IOException;import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class StuActivity extends Activity
{
     String nameSpace = "http://tempuri.org/";
      String methodName = "HelloWorld";
      String url = "http://www.stu80.com/hello.asmx";
    private EditText txt1;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txt1 = (EditText) findViewById(R.id.txt1);
        // 调用的方法
        String methodName = "HelloWorld";
        // 创建HttpTransportSE传输对象
        HttpTransportSE ht = new HttpTransportSE(url);
        ht.debug = true;
        // 使用SOAP1.1协议创建Envelop对象
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11 );        
        // 实例化SoapObject对象
        SoapObject soapObject = new SoapObject(nameSpace, methodName);
    //    soapObject.addProperty("param", "1");
        // 将soapObject对象设置为 SoapSerializationEnvelope对象的传出SOAP消息
        envelope.bodyOut = soapObject;
        
        try
        {
            // 调用Web Service
            ht.call(null,  envelope);
            if (envelope.getResponse() != null)
            {
                // 获取服务器响应返回的SOAP消息
                SoapObject result = (SoapObject) envelope.bodyIn;
                txt1.setText(result.toString());    
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (XmlPullParserException e)
        {
            e.printStackTrace();
        }
    }
}
问题是报错怎么做?web service 地址  http://www.stu80.com/hello.asmx,大家可以试试,寻找解决方法

解决方案 »

  1.   

    改两处1 envelope.dotNet = true; //加上这句话,申明服务端为.net
    2 ht.call(nameSpace+methodName,  envelope); //第一个参数action的值为命名空间+方法名
      

  2.   


    你还来劲了,又不是什么非常复杂的web service,就一个asp.net创建web service时的默认的Hello World
    函数,主程序就这么几行,,也可以复制啊,又不要手打的main.xml 就一个TextView啊,又不是很多很多既然你这么说了,那我也要说了,你就不能新建一个android项目,调试一下啊不说就算了,反正浪费了几百分了,不差这100分。。