0
所以即時嘗試這個HttpResponseMessage,它工作正常,只要我不放任何內容屬性。但是我現在需要它在郵件的內容中返回一個json。HttpResponseMessage在內容屬性填充時不起作用
我的代碼如下所示:
public HttpResponseMessage GetMemberById()
{
string id = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["id"];
List<ClubMember> ls = KCBLL.Instance.FindMemberById(id);
HttpResponseMessage MessageRetour = new HttpResponseMessage();
if (ls.Count == 1)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(ls.First());
MessageRetour.Content = new StringContent(json, Encoding.UTF8);
MessageRetour.StatusCode = HttpStatusCode.OK;
return MessageRetour;
}
}
接口
[OperationContract]
[WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "GetMemberById")]
HttpResponseMessage GetMemberById();
最後類
[DataContract]
public class ClubMember
{
[DataMember]
public long MemberId { get; set; }
[DataMember]
public string MemberNumber { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
任何幫助,將不勝感激
也試着返回一個消息類型,我仍然得到一個「無法得到任何迴應」 – user3404416