试图将datatable参数传递给webservice(asmx)方法,但出现以下错误:
{“消息”:“类型\ u0027System.Collections.Generic.IDictionary`2 [[System.String,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[System.Object,mscorlib,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b77a5c561934e089]] \ u0027不支持数组反序列化。“,” StackTrace“:”位于System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList列表,类型类型,JavaScriptSerializer序列化器,布尔型throwOnError,IList \ u0026 convertedList)\ r \ n位于System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o,Type type,JavaScriptSerializer序列化器,布尔型throwOnError,Object \ u0026 convertedObject)\ r \ System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o,Type type,JavaScriptSerializer serializer,Boolean throwOnError,Object \ u0026 conversionObject)在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer序列化器处为n ,字符串输入t,类型类型,Int32 depthLimit)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.Deserialize [T](字符串输入)\ r \ n在System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext上下文) ,JavaScriptSerializer序列化程序)\ r \ n(位于System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData,HttpContext上下文))\ r \ n位于System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData) “,” ExceptionType“:” System.InvalidOperationException“}
我正在将数据表序列化为json对象,并将其通过http请求传递
Request Code:
var dsAttendance= GetBioMetricData();
string jsonData;
//here dsAttendance is dataset in which only one table is available
if (dsAttendance != null && dsAttendance.Tables.Count != 0)
{
jsonData =
JsonConvert.SerializeObject(dsAttendance.Tables[0]);
}
else
{
jsonData = null;
}
var content = new StringContent(jsonData);
var url =
ConfigurationManager.AppSettings["ClientSettingsProvider.ServiceUri"];
var response = await Request(HttpMethod.Post, url+
"/AttendanceLiveData", jsonData, new Dictionary<string, string>());
string responseText = await
response.Content.ReadAsStringAsync();
static async Task<HttpResponseMessage> Request(HttpMethod pMethod, string
pUrl, string pJsonContent, Dictionary<string, string> pHeaders)
{
var httpRequestMessage = new HttpRequestMessage();
httpRequestMessage.Method = pMethod;
httpRequestMessage.RequestUri = new Uri(pUrl);
foreach (var head in pHeaders)
{
httpRequestMessage.Headers.Add(head.Key, head.Value);
}
switch (pMethod.Method)
{
case "POST":
HttpContent httpContent = new StringContent(pJsonContent,
Encoding.UTF8, "application/json");
httpRequestMessage.Content = httpContent;
break;
}
return await client.SendAsync(httpRequestMessage);
}
Web Service Code:
[WebMethod(EnableSession = true)]
public string AttendanceLiveData(object dsAttendnceData)
{
if (dsAttendnceData != null)
{
return "true";
}
else
{
return null;
}
}
需要通过Web服务方法从httppost请求传递的数据表