Generate JSON array with WCF

前端 未结 2 1831
悲哀的现实
悲哀的现实 2021-01-22 15:46

I\'m developing a WCF web service that returns this:

{
    \"allFormsResult\": [
        {
            \"FormId\": 1,
            \"FormName\": \"Formulario 1\"
         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-22 16:17

    The problem is here:

    namespace ADM
    {
        [ServiceContract]
        public interface IRestServiceImpl
        {
            [OperationContract]
            [WebInvoke(Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Wrapped,
                UriTemplate = "forms/")]
            List allForms();
        }
    }
    

    I have to use it this way:

    namespace ADM
    {
        [ServiceContract]
        public interface IRestServiceImpl
        {
            [OperationContract]
            [WebInvoke(Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "forms/")]
            List allForms();
        }
    }
    

    Changing BodyStyle:

    BodyStyle = WebMessageBodyStyle.Bare
    

提交回复
热议问题