hi all,
how to solve my error,
{"Message":"Cannot convert object of type \u0027System.String\u0027 to type \u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\u0027","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
calling web method using jquery,
my script code like
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#btnok").click(function () {
alert('');
var username = $("#name").val();
var password = $("#password").val();
var clientid = $("#clientid").val();
var data = { username: $("#name").val(), password: $("#password").val(), clientid: $("#clientid").val() };
var data = JSON.stringify(data);
alert(data);
$.ajax({
type: "POST",
url: "http://localhost:3658/HostingService.asmx/SETusers",
data: JSON.stringify(data),
contentType: "application/json;charset=utf-8",
processData: false,
dataType: "json",
success: function (data) {
alert('Success');
},
error: function (data, status, error) {
alert(data.responseText);
}
});
});
});
</script>
my html code,
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="form3">
<tr>
<td width="25%" align="left" valign="middle">
USERNAME
</td>
<td width="75%" align="left" valign="middle">
<input id="name" type="text" class="textbox2" name="name" size="30" />
</td>
</tr>
<tr>
<td align="left" valign="middle">
PASSWORD
</td>
<td align="left" valign="middle">
<input id="password" type="text" class="textbox2" name="name" size="30" />
</td>
</tr>
<tr>
<td align="left" valign="middle">
CLIENTID
</td>
<td align="left" valign="middle">
<input id="clientid" type="text" class="textbox2" name="name" size="30" />
</td>
</tr>
<tr>
<td>
<input id="btnok" name="Submit" type="button" value="Submit" class="btn2" border="0" />
</td>
</tr>
</table>
my web services code is,
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json,UseHttpGet=false)]
public string SETusers(string username, string password,string clientid)
{ DataSet ds = new DataSet();
try
{
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = new SqlCommand();
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Connection = (SqlConnection)OpenConnection1();
adp.SelectCommand.CommandText = "SP_USERDETAILS_SET";
SqlParameter[] Parameters = new SqlParameter[3];
Parameters[0] = new SqlParameter("@NAME", SqlDbType.VarChar,50);
Parameters[0].Value = username;
Parameters[1] = new SqlParameter("@PASSWORD", SqlDbType.VarChar, 50); Parameters[1].Value = password;
Parameters[2] = new SqlParameter("@CLIENT_ID", SqlDbType.Int);
Parameters[2].Value =Convert.ToInt32(clientid);
adp.SelectCommand.Parameters.AddRange(Parameters);
adp.Fill(ds);
string[][] JaggedArray = new string[ds.Tables[0].Rows.Count][];
List<object> resultMain = new List<object>();
foreach (DataRow rs in ds.Tables[0].Rows)
{
Dictionary<string,> result = new Dictionary<string,>(); foreach (DataColumn dc in ds.Tables[0].Columns)
{
result.Add(dc.ColumnName, rs[dc].ToString());
}
resultMain.Add(result);
}
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(resultMain);
return strJSON;
}
catch
{
CloseConnection1();
return "-1";
}
finally
{
CloseConnection1();
}
}