急急急,关于android调用net webservice的问题,在线等

jan_five2012 2014-02-21 02:48:45
先上代码:
1、net的webservice代码
[WebService(Namespace = "http://iscan.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class IScanConn : System.Web.Services.WebService
{
public MySoapHeader myheader = new MySoapHeader();
public JSONHelper jsonHelper = new JSONHelper();

//[SoapHeader("myheader")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]//返回json
[WebMethod(Description = "登录系统", EnableSession = true), SoapRpcMethod(Use = System.Web.Services.Description.SoapBindingUse.Literal)]
public string Login(string username, string userpassword)
{
logGet(username);
logGet(userpassword);
A040X10YGJBXXDAO dao = null;
string msg = "";
//验证是否有权访问
//if (!myheader.isValid(out msg))
//{
// logGet(msg);
// dao.B030dlmcXX = msg;
//}
//else
//{
A040X10YGJBXXBLL ygbll = new A040X10YGJBXXBLL();
bool b = ygbll.CheckPassword(username, userpassword);
if (b)
{
int id = ygbll.GetIdA040X10YGJBXX(username);
dao = ygbll.GetModel(Convert.ToInt64(id));
}
//}
List<A040X10YGJBXXDAO> listDao = new List<A040X10YGJBXXDAO>();
listDao.Add(dao);
logGet("end");
msg = jsonHelper.GetJson<List<A040X10YGJBXXDAO>>(listDao);
logGet(msg);
return msg;
}

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]//返回json
[WebMethod(Description = "登录系统1", EnableSession = true), SoapRpcMethod(Use = System.Web.Services.Description.SoapBindingUse.Literal)]
public string Login1()
{
logGet("1");
A040X10YGJBXXDAO dao = null;
A040X10YGJBXXBLL ygbll = new A040X10YGJBXXBLL();
dao = ygbll.GetModel(1);
logGet("end");
List<A040X10YGJBXXDAO> listDao = new List<A040X10YGJBXXDAO>();
listDao.Add(dao);
string msg = jsonHelper.GetJson<List<A040X10YGJBXXDAO>>(listDao);
logGet(msg);
return msg;
}

2、android客户端代码
public static String GetMsg(String[] args)  {
Log.v(l_tag, "star");
//webservice地址
final String endpoint="http://10.0.2.2:8082/IScanWS/IScanConn.asmx";
// 调用的方法
final String methodName = "Login";

List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
JSONObject json = new JSONObject();
try {
json.put("username", args[0]);
} catch (JSONException e) {
e.printStackTrace();
}
try {
json.put("userpassword", args[1]);
} catch (JSONException e) {
e.printStackTrace();
}
try
{
Log.v(l_tag, "call");
String msg = SoapHelper.GetResponse(methodName, params, endpoint);
Log.v(l_tag, "callback");
if (msg != null)
{
// 获取服务器响应返回的SOAP消息
//JSONArray json_arr = new JSONArray(msg);
//JSONObject json_obj = (JSONObject) json_arr.get(0);

//String id = json_obj.getString("B990sbgjzX")
Log.v(l_tag, msg);
return msg;
}else{
return "Null";
}
}
/*catch (IOException e)
{
e.printStackTrace();
return e.getLocalizedMessage();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
return e.getLocalizedMessage();
} */
catch (Exception e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
public static String GetResponse(String method,List<BasicNameValuePair> params,String wsurl)
{
try {
String WSUrl=wsurl;
String url = WSUrl;

// 实例化SoapObject对象
SoapObject request = new SoapObject(namespace, method);
if (params.size() > 0){
// 添加请求参数
for(int i=0,len=params.size();i<len;i++){
request.addProperty(params.get(i).getName(),
params.get(i).getValue());
}
}
// 使用SOAP1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// 设置与.Net提供的Web Service保持较好的兼容性,适用rpc模式设置false
envelope.dotNet = true;
//设置请求参数
envelope.setOutputSoapObject(request);
// 创建HttpTransportSE传输对象
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call(namespace + method, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
return result.toString();
} catch (Exception e) {
System.out.println(e.getMessage());
return "Error:调用web services出错!"+e.getMessage();
}
}


问题描述:
可以成功访问到我的webservice,没有参数可以得到返回的结果,带参数的情况下,webservice没有接收到终端发来的参数,不知道是什么问题。
附图:androidlog错误日志


附图:终端程序运行到最后就自动停止了


麻烦大大们给看下,非常感谢
...全文
131 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,977

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧