我有一个代码:
Session["timestamp"] 中有一个字节数组,使用 LInq to Entity
现在当我调用这个函数时它抛出一个错误
Web 服务的签名如下:
[WebMethod]
public string IsRowChanged(int en_id , byte[] timestamp)
{
}
如果我将 byte[] 替换为 string 就可以了。
$.ajax({
type: "POST",
url: "UpdateEntityService.asmx/IsRowChanged",
data: "{ 'en_id':'" + '<%= Request.QueryString["entity_id"] == null ? "1" : Request.QueryString["entity_id"] %>' + "' , 'timestamp': '" + '<%= (Session["timestamp"]) %>' + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var result = msg.d;
if (result == "0") {
save_valid();
$.prompt("Data Saved Sucessfully");
}
else {
$.prompt("Data Concurrency Error! Reload the Page.. by pressing F5");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(textStatus);
alert(errorThrown);
}
});
感谢任何帮助。
最佳答案
您应该对二进制数据进行 Base 编码,然后在服务器端将其转换回 byte[]。
// returns a byte[]
System.Convert.FromBase64String(base64String);
// returns a string
System.Convert.ToBase64String(byteData);
关于c# - 通过 JSON 对象将 session 对象中的字节数组传递给 Web 服务(Asp.Net 2.0 asmx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7802681/