我服务器端是Asp.net的WebService服务,有增删改查方法,在android里边调用的webService方法,我传递参数的操作数据库的时候结果怎么是乱码?
在Antivity传递参数之前我打印XML字符串是正确的,到了WebService里边就Over啦,哦,对了,我的XML字符串是utf-8编码格式,这是传递参数并调用WebService方法cPropertys.addProperty("name", edtKeyWord.getText());
XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
XmlPullParser xmlpull=factory.newPullParser();
InputStream inputString=websCaller.CallWebservice("GetAllUserByName",cPropertys);
这里是打印并传递XML字符串 String xmlInfo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+" <soap:Body>"
+ "<" + WebMethod + " xmlns=\"" + WebServiceNameSpace + "\">" + StrPro + "</" + WebMethod + ">"
+"</soap:Body>"
+"</soap:Envelope>";System.out.println(new String(xmlInfo.getBytes("utf-8")));
out.write(new String(xmlInfo.getBytes("utf-8")));
out.flush();
out.close();
我WebService服务里边的GetAllUserByName方法为: [WebMethod(Description = "根据姓名查询人员返回List集合")]
public List<UserEntity> GetAllUserByName(string name)
{
http_name = name;
string sql = "select * from xcm_code_user where 1=1 ";
if (name == "" || name == null)
{
sql += "";
}
else
{
sql += " and u_name like '%" + name + "%'";
}
List<UserEntity> list = new List<UserEntity>();
DataTable dt = DBHelper.GetDataTableBySql(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
UserEntity user = new UserEntity();
user.U_id = int.Parse(dt.Rows[i]["u_id"].ToString());
user.U_name = dt.Rows[i]["u_name"].ToString();
user.U_pass = dt.Rows[i]["u_pass"].ToString();
user.U_qx = dt.Rows[i]["u_qx"].ToString();
user.U_enable = dt.Rows[i]["u_enable"].ToString();
user.U_phone = dt.Rows[i]["u_phone"].ToString();
list.Add(user);
}
return list;
}
在Antivity传递参数之前我打印XML字符串是正确的,到了WebService里边就Over啦,哦,对了,我的XML字符串是utf-8编码格式,这是传递参数并调用WebService方法cPropertys.addProperty("name", edtKeyWord.getText());
XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
XmlPullParser xmlpull=factory.newPullParser();
InputStream inputString=websCaller.CallWebservice("GetAllUserByName",cPropertys);
这里是打印并传递XML字符串 String xmlInfo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+" <soap:Body>"
+ "<" + WebMethod + " xmlns=\"" + WebServiceNameSpace + "\">" + StrPro + "</" + WebMethod + ">"
+"</soap:Body>"
+"</soap:Envelope>";System.out.println(new String(xmlInfo.getBytes("utf-8")));
out.write(new String(xmlInfo.getBytes("utf-8")));
out.flush();
out.close();
我WebService服务里边的GetAllUserByName方法为: [WebMethod(Description = "根据姓名查询人员返回List集合")]
public List<UserEntity> GetAllUserByName(string name)
{
http_name = name;
string sql = "select * from xcm_code_user where 1=1 ";
if (name == "" || name == null)
{
sql += "";
}
else
{
sql += " and u_name like '%" + name + "%'";
}
List<UserEntity> list = new List<UserEntity>();
DataTable dt = DBHelper.GetDataTableBySql(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
UserEntity user = new UserEntity();
user.U_id = int.Parse(dt.Rows[i]["u_id"].ToString());
user.U_name = dt.Rows[i]["u_name"].ToString();
user.U_pass = dt.Rows[i]["u_pass"].ToString();
user.U_qx = dt.Rows[i]["u_qx"].ToString();
user.U_enable = dt.Rows[i]["u_enable"].ToString();
user.U_phone = dt.Rows[i]["u_phone"].ToString();
list.Add(user);
}
return list;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货