本帖最后由 azhe0929 于 2011-10-14 09:57:20 编辑

解决方案 »

  1.   

    返回的body信息里面就是
    什么啊?怎么这里也没写全?
      

  2.   


    返回的body信息是  无权使用,也就是
    if (name == "user" || password == "password")
                {
                    return true;
                }
                else
                {
                    msg = "您无权使用此服务";
                    return false;
                }
            }
    else里面的那个 您无权使用
      

  3.   

    后来我改了下,webservice里面的(直接把我服务端贴了)
    using System;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;[WebService(Namespace = "http://tempuri.org/HelloWorld")]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
    //这是对于SoapAction的处理,问题不在这里
    //[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    [SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    public class Service : System.Web.Services.WebService
    {
        //创建Soapheader
        public MySoapHeader mySoapHeader;    public Service()
        {        //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }    [SoapRpcMethod, WebMethod(MessageName = "HelloWorld")]//具体方法中也要指定rpc方式
        public string Hello()
        {
            return "Hello World";
        }
        [SoapHeader("mySoapHeader", Direction = SoapHeaderDirection.In)]
        [SoapRpcMethod, WebMethod(MessageName = "Json")]//具体方法中也要指定rpc方式
        public string GetUserDate(string sqlstr)
        {
            string msg = string.Empty;
            if (mySoapHeader != null)
            {            if (mySoapHeader.IsValid(out msg))
                {                sqlconn sqlconn = new sqlconn();
                    DataTable selDt = sqlconn.getSelDate(sqlstr);
                    String json = ToJson.DataTableToJson("json", selDt);
                    return json;
                }
                else
                {
                    return msg;//返回错误信息
                }        }
            else
                return "Soap头信息无效";    }
        [SoapRpcMethod, WebMethod(MessageName = "compress")]//具体方法中也要指定rpc方式
        public Byte[] NewGetUserDate(string sqlstr)
        {
            sqlconn sqlconn = new sqlconn();
            DataTable selDt = sqlconn.getSelDate(sqlstr);
            String strjson = ToJson.DataTableToJson("json", selDt);        //字符串转换
            byte[] bytejson = System.Text.Encoding.Unicode.GetBytes(strjson);
            GzipCompress gzipcompress = new GzipCompress();
            byte[] compressedbytejson = gzipcompress.Compress(bytejson);
            return compressedbytejson;
            // return Convert.FromBase64CharArray(compressedbytejson);    }
    }
    //SoapHead类定义public class MySoapHeader : System.Web.Services.Protocols.SoapHeader
    {
        private string name;
        private string password;    public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        /// <summary>
        /// 校验soaphead信息
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="msg">返回信息</param>
        /// <returns>是否正确</returns>
        public bool IsValid(string name, string password, out string msg)
        {
            msg = "";
            try
            {
                if (name == "user" || password == "password")
                {
                    return true;
                }
                else
                {
                    msg = name+password+"无权使用此服务";
                    return false;
                }
            }
            catch
            {
                msg =name+password+ "您无权使用此服务";
                return false;
            }
        }
        public bool IsValid(out string msg)
        {
            return IsValid(name, password, out msg);
        }}前面的那个//[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
    [SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)],这时候,Mysoaphead那个不为空了,也就是被初始化了,但是里面的值依然为空,依然没有值
      

  4.   

    自己搞定了,哈哈,原来是在.net端 不能指定用RPC模式,而且envelope.dotNet = true;自己顶自己的努力!!
      

  5.   

    楼主能不能共享一下您使用的jar包 ksoap2