当前位置: 代码迷 >> Android >> 重新开贴,不算这次,已经花了150分了,还没答案,寻找web service连接高手解决办法
  详细解决方案

重新开贴,不算这次,已经花了150分了,还没答案,寻找web service连接高手解决办法

热度:105   发布时间:2016-05-01 21:16:06.0
重新开贴,不算这次,已经花了150分了,还没答案,寻找web service连接高手
C# code
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 service

Java code
package 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,

大家可以试试,寻找解决方法

------解决方案--------------------
改两处
Java code
1 envelope.dotNet = true; //加上这句话,申明服务端为.net2 ht.call(nameSpace+methodName,  envelope); //第一个参数action的值为命名空间+方法名
------解决方案--------------------
你太看得起你自己了。 还踊跃回答。分数能当饭吃?
人家才叫你贴个报错日志上来,你看你是什么态度?
不管别人帮不帮得了你,也不管你之前用了多少分去问别人同样的问题,
首先你的态度就不对,这个帖子我就是第一次浏览,你的问题我也是第一次看见,
学习态度要诚恳,不懂怎么解决可以,但不要连怎么提问都不懂好吧,
我给出了解决的方案,我的项目就是这么写,你来句:不行的,什么都没有了,
大家踊跃回答。你起码要告诉别人,你遇到的问题是什么,别把代码贴出来就8点以前分就给你了。
  相关解决方案