1,979
社区成员




[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;
}
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();
}
}