我的服务中有几个“发布”操作合同,需要接收多个参数。我使用Json作为格式。想知道是否
例如
[ServiceContract]
public interface ICalendarService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Event?eventId={eventId}&consumer={consumer}")]
Event GetEvent(int eventId, string consumer);
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
bool UpdateEventDetails(Event event);
}
[DataContract]
public class Event{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Notes { get; set; }
[DataMember]
public bool Private { get; set; }
[DataMember]
public string Date { get; set; }
[DataMember]
public int AuditedById { get; set; }
}
答案 0 :(得分:0)
Event类中不需要[DataContract]
和[DataMember]
属性。
使用以下属性
装饰您的界面方法[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped)]