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