Create on Datasource transport never fires WCF rest method

2 posts, 0 answers
  1. Rod
    Rod avatar
    9 posts
    Member since:
    Jan 2013

    Posted 29 Jan 2013 Link to this post

    I currently have an example that fires my delete, update, and read methods on my WCF rest service. For whatever reason, I cannot get the create to work. Am I doing something wrong?

    <script>
            $(document).ready(function () {
                var crudServiceBaseUrl = "http://localhost/IqaRestService/Service1",
                dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: crudServiceBaseUrl + "/getquestions",
                            dataType: "json"
                        },
                        update: {
                            url: crudServiceBaseUrl + "/update",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json"
                        },
                        create: {
                            url: crudServiceBaseUrl + "/create",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json"
                        },
                        destroy: {
                            url: crudServiceBaseUrl + "/delete",
                            dataType: "json",
                            type: "DELETE",
                            contentType: "application/json"
                        },
                        parameterMap: function (options, operation) {
                            if (operation !== "read" && options) {
                                return kendo.stringify({ question: options });
                            }
                        }
                    },
                    schema: {
                        model: {
                            id: "QuestionId",
                            fields: {
                                QuestionId: { type: "string" },
                                QuestionText: { type: "string" },                           
                                Comment: { type: "string" },
                                Answer: { type: "string" }
                            }
                        }
                    }
                });
     
                $(".k-add-button").click(function (e) {
                    listView.add();
                    e.preventDefault();
                });
     
                var listView = $("#listView").kendoListView({
                    dataSource: dataSource,
                    editable: true,
                    selectable: "single",
                    template: kendo.template($("#template").html()),               
                    editTemplate: kendo.template($("#editTemplate").html())
                }).data("kendoListView");
     
            });
        </script>
    [OperationContract]
            [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/getquestions")]
            public List<IqaQuestion> GetQuestions()
            {
                return this.Store;           
            }
     
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/update", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            public bool SaveQuestion(IqaQuestion question)
            {           
                return true;
            }
     
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "/create", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            public bool CreateQuestion(IqaQuestion question)
            {           
                return true;
            }
     
            [OperationContract]
            [WebInvoke(Method = "DELETE", UriTemplate = "/delete", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
            public bool RemoveQuestion(IqaQuestion question)
            {
                return false;
            }
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 31 Jan 2013 Link to this post

    Hello Rod,

    Thank you for getting in touch with us.

    I am not sure exactly where the problem comes from. Your Kendo configuration looks OK, so I assume that the problem might be connected with IDs of the records. A record will be synchronized through the create transport only if its ID value is empty. You can verify whether a given dataSource model is new with the isNew method.

    Are you setting the QuestionId field on the client? Is the newly created record submitted via update request?

    You may also find this forum thread useful as it discusses editing and IDs.

    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
Back to Top