Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Restful service parse enum within json cause error
    text
    copied!<p>I have a restful service based on WCF like below: (The FeedbackInfo class has only one <code>enum</code> member - ServiceCode.)</p> <pre><code>[OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public List&lt;FeedbackInfo&gt; GetFeedbackInfoList(ServiceCode code) { return ALLDAO.GetFeedbackInfoList(code); } [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public int? CreateFeedback(FeedbackInfo feedback) { return ALLDAO.CreateFeedback(feedback); } </code></pre> <p>I will use jquery ajax to invoke these two method like below:</p> <pre><code>$.ajax({ type: "GET", url: "/Service/ALL.svc/GetFeedbackInfoList", datatype: "text/json", data: { "code": "Info"}, }); var feedbackInfo = { feedback: { ServiceCode: "Info" }}; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "/Service/ALL.svc/CreateFeedback", datatype: "text/json", data: JSON.stringify(feedbackInfo), }); </code></pre> <p>The first calling will be excuted succesfully, whereas the second one give me an error: The value "Info" cannot be parsed as the type 'Int64'. I'm wondering why the same one enum can not be parsed in the second calling? Just because of the enum type being used as a member of class?</p> <p><strong>EDIT:</strong> The FeedbackInfo and ServiceCode are looked like below:</p> <pre><code>public class FeedbackInfo { public int ID { get; set; } public string Title { get; set; } public ServiceCode ServiceCode { get; set; } } [DataContract] public enum ServiceCode { [EnumMember] Info, [EnumMember] Error } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload