Answered by:
Cant call WebMethod

Question
-
User2134858266 posted
function SignOut() { $.ajax({ type:"POST", async: false, url: "ShareServices.asmx/SignOut", data: "{}", contentType: "application/json; charset=utf-8", datatype: "json", success: function () { }, error: function (jqXHR, textStatus, errorThrown) { } }); } [WebMethod] [ScriptMethod] public void SignOut() { HttpContext.Current.Session.Abandon(); HttpContext.Current.Response.Redirect("Login.aspx"); }
SignOut Method doesnt get called no matter what options I use.
Saturday, November 23, 2013 11:04 PM
Answers
-
User1079421601 posted
Use like following. This is a sample example from my running application.
Script
/*Save Data*/ function SaveData() { var roleInfoList = []; var len = $('#gvRoleInfo tr').length; var count = 0; $('#gvRoleInfo tr').each(function() { if (!this.rowIndex) return; // Skip first row var flag = $(this).find('.uflag').text(); if(flag == 1) return; //Object should not create if it is unchanged item var rolNm = $(this).find('.roleName').text(); var id = $(this).find('.roleId').text(); var roleInfo = { roleNm: rolNm, roleId: id, updateFlag: flag}; roleInfoList[count] = roleInfo; count++; }); if(roleInfoList.length < 1) return; $.ajax({ type: "POST", url: "Services/ApplicationService.asmx/SaveRoleInfo?refCode=RoleInfo", data: "{'roleInfoList':" + JSON.stringify(roleInfoList) + "}", contentType: "application/json; charset=utf-8", dataType: "json", error: function(xhr, errorType, exception) { var err = eval("(" + xhr.responseText + ")"); //Display Error Message. alert(err.Message); }, success: function(msg) { getAllRollInfo(); alert(msg.d); }, failure: function() { alert("System can not retrive data \nPlease contact with system administrator" + "\nHints: Webservice didn't response."); } }); }
C# code, Web service
public class ApplicationService : System.Web.Services.WebService { private readonly IRoleInfoBLL _objRoleInfoBLL; public ApplicationService() { string strModelName = Context.Request.QueryString["refCode"]; else if (strModelName == "RoleInfo") { _objRoleInfoBLL = StructureMap.ObjectFactory.GetNamedInstance<IRoleInfoBLL>("RoleInfoBLL"); } } [WebMethod] public string SaveRoleInfo(List<object> roleInfoList) { string message = ""; foreach (var roleInfo in roleInfoList) { object roleInfoObj = roleInfo; Dictionary<string, object> tmp = (Dictionary<string, object>)roleInfoObj; object rl_flag = null; object rl_id = null; object rl_nm = null; tmp.TryGetValue("updateFlag", out rl_flag); tmp.TryGetValue("roleId", out rl_id); tmp.TryGetValue("roleNm", out rl_nm); int uFlag = Convert.ToInt32(rl_flag.ToString()); int roleId = Convert.ToInt32(rl_id.ToString()); string roleNm = rl_nm.ToString(); if (uFlag == 1) // For existing data continue; RoleInfo objRoleInfo = new RoleInfo(); objRoleInfo.Role_Id = roleId; objRoleInfo.RoleName = roleNm; objRoleInfo.UserId = 1; // Hard Coded ... Should come from session user id// if (uFlag == 2) // For New insert { try { message = _objRoleInfoBLL.SaveRoleInfo(objRoleInfo); } catch (Exception exp) { throw (exp); } } else if (uFlag == 3) //For Update { try { message = _objRoleInfoBLL.EditRoleInfo(objRoleInfo); } catch (Exception exp) { throw (exp); } } } return message; } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, November 24, 2013 2:11 AM
All replies
-
User197322208 posted
put an
window.alert(textStatus)
on the error function. What's the error?
Sunday, November 24, 2013 1:50 AM -
User1079421601 posted
Use like following. This is a sample example from my running application.
Script
/*Save Data*/ function SaveData() { var roleInfoList = []; var len = $('#gvRoleInfo tr').length; var count = 0; $('#gvRoleInfo tr').each(function() { if (!this.rowIndex) return; // Skip first row var flag = $(this).find('.uflag').text(); if(flag == 1) return; //Object should not create if it is unchanged item var rolNm = $(this).find('.roleName').text(); var id = $(this).find('.roleId').text(); var roleInfo = { roleNm: rolNm, roleId: id, updateFlag: flag}; roleInfoList[count] = roleInfo; count++; }); if(roleInfoList.length < 1) return; $.ajax({ type: "POST", url: "Services/ApplicationService.asmx/SaveRoleInfo?refCode=RoleInfo", data: "{'roleInfoList':" + JSON.stringify(roleInfoList) + "}", contentType: "application/json; charset=utf-8", dataType: "json", error: function(xhr, errorType, exception) { var err = eval("(" + xhr.responseText + ")"); //Display Error Message. alert(err.Message); }, success: function(msg) { getAllRollInfo(); alert(msg.d); }, failure: function() { alert("System can not retrive data \nPlease contact with system administrator" + "\nHints: Webservice didn't response."); } }); }
C# code, Web service
public class ApplicationService : System.Web.Services.WebService { private readonly IRoleInfoBLL _objRoleInfoBLL; public ApplicationService() { string strModelName = Context.Request.QueryString["refCode"]; else if (strModelName == "RoleInfo") { _objRoleInfoBLL = StructureMap.ObjectFactory.GetNamedInstance<IRoleInfoBLL>("RoleInfoBLL"); } } [WebMethod] public string SaveRoleInfo(List<object> roleInfoList) { string message = ""; foreach (var roleInfo in roleInfoList) { object roleInfoObj = roleInfo; Dictionary<string, object> tmp = (Dictionary<string, object>)roleInfoObj; object rl_flag = null; object rl_id = null; object rl_nm = null; tmp.TryGetValue("updateFlag", out rl_flag); tmp.TryGetValue("roleId", out rl_id); tmp.TryGetValue("roleNm", out rl_nm); int uFlag = Convert.ToInt32(rl_flag.ToString()); int roleId = Convert.ToInt32(rl_id.ToString()); string roleNm = rl_nm.ToString(); if (uFlag == 1) // For existing data continue; RoleInfo objRoleInfo = new RoleInfo(); objRoleInfo.Role_Id = roleId; objRoleInfo.RoleName = roleNm; objRoleInfo.UserId = 1; // Hard Coded ... Should come from session user id// if (uFlag == 2) // For New insert { try { message = _objRoleInfoBLL.SaveRoleInfo(objRoleInfo); } catch (Exception exp) { throw (exp); } } else if (uFlag == 3) //For Update { try { message = _objRoleInfoBLL.EditRoleInfo(objRoleInfo); } catch (Exception exp) { throw (exp); } } } return message; } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, November 24, 2013 2:11 AM -
User879079649 posted
Make sure that you have un commented the following class attribute in your service class so that it will allow Scripts/Ajax calls.
[System.Web.Script.Services.ScriptService]
Sunday, November 24, 2013 6:03 AM