Android调用webservice里面的soaphead校验问题,解决方案有没有 本帖最后由 azhe0929 于 2011-10-14 09:57:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 返回的body信息里面就是什么啊?怎么这里也没写全? 返回的body信息是 无权使用,也就是if (name == "user" || password == "password") { return true; } else { msg = "您无权使用此服务"; return false; } }else里面的那个 您无权使用 后来我改了下,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那个不为空了,也就是被初始化了,但是里面的值依然为空,依然没有值 自己搞定了,哈哈,原来是在.net端 不能指定用RPC模式,而且envelope.dotNet = true;自己顶自己的努力!! 楼主能不能共享一下您使用的jar包 ksoap2 android编译时没错误,但是不能执行,求救! Win7下NDKR7b&&Cygwin,编译libiconv-1.14 程序再也无法运行了。 android 照相问题 申请API,为啥会这样子啊 没有为类型 Camera 定义方法 open() Android代码动态布局生成通知 android 网络通信-近乎社区团队出品 关于安卓app页面切换的问题,急求大神解决 android问题欢乐多 问android上关于蓝牙和3G的低级问题 关于bundle的问题
什么啊?怎么这里也没写全?
返回的body信息是 无权使用,也就是
if (name == "user" || password == "password")
{
return true;
}
else
{
msg = "您无权使用此服务";
return false;
}
}
else里面的那个 您无权使用
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那个不为空了,也就是被初始化了,但是里面的值依然为空,依然没有值