我有这样的服务:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "DoWork", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Person DoWork(Person person);
}
服务实现如下:
public class Service : IService
{
public Person DoWork(Person person)
{
//To do required function
return person;
}
}
我的Person
类型定义是:
[DataContract]
public class Person
{
[DataMember]
public string Name { get; set; }
}
我尝试使用 jQuery 使用此服务:
var data = { 'person': [{ 'Name': 'xxxxx'}] };
$.ajax({
type: "POST",
url: URL, // Location of the service
data: JSON.stringify(data), //Data sent to server
contentType: "application/json", // content type sent to server
dataType: "json", //Expected data format from server
processData: false,
async: false,
success: function (response) {
},
failure: function (xhr, status, error) {
alert(xhr + " " + status + " " + error);
}
});
我可以使用它来调用服务,但是参数 (Person
服务方法的参数(对象)DoWork
始终为 NULL。我怎样才能解决这个问题?