WCF服务,我有这样的服务:消费与复合型
[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);
}
});
我可以使用此调用服务,但服务方法DoWork
的参数(Person
对象)始终为NULL。我怎样才能解决这个问题?
显示你'Person'类型定义。 – jwaliszko
[DataContract] public class Person { [DataMember] public string Name {get;组; } } – user2567909