开发者

Invalid web service call, missing value for parameter with Backbone and Webservice webmethods

开发者 https://www.devze.com 2023-04-11 06:33 出处:网络
Is it possible for backbone to interface with asp.net soap webservice methods for saving and retrieving the data? because i got this error from the webmethod but actually the POST contains the paramet

Is it possible for backbone to interface with asp.net soap webservice methods for saving and retrieving the data? because i got this error from the webmethod but actually the POST contains the parameters.

Server Side

[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static Dummy SaveDummy(Dummy myDummy)
        {
            Dummy dumdum = myDummy;
            HttpContext.Current.Session["data"] = dumdum;
            return myDummy;
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
        public static Dummy FetchDummy()
        {
            return (Dummy)HttpContext开发者_JAVA技巧.Current.Session["data"];
        }

        public class Dummy
        {
            private string _name;
            private string _script;

            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }

            public string Script
            {
                get
                {
                    return _script;
                }
                set { _script = value; }
            }
        }

Backbone Model

  window["model"] = Backbone.Model.extend({
        initialize: function () {
            console.log("CREATED");
        },
        defaults:{
            name:"Please enter your name",
            script:"Hello World"
        },
        urlRoot: "index.aspx/SaveDummy",
        validate: function (attrs) {

        }
    });

Application

$("document").ready(function () {

    var myModel = new model({
        name: "Stack Overflow",
        script: "alert('Hi SO')"
    });

    var myView = new view({
        model: myModel,
        el: $("#placeholder")
    });

    console.log("SAVING");
    myModel.save();

    console.log("FETCHING");
    myModel.fetch();

POST

{"name":"Stack Overflow","script":"alert('Hi SO')"}

Message

Invalid web service call, missing value for parameter: 'myDummy'.

Note

I did look into other posts with similar problem, which were solved by doing something like {myDummy={"name":"Stack Overflow","script":"alert('Hi SO')"}} . How could this be generated using Backbone?


All of the server-side synchronization in Backbone is handled through Backbone.Sync which is designed for two things:

  • REST apis that work with JSON (not SOAP/XML)
  • Extensibility

So you will need to override the Backbone.Sync behavior to talk to your backend. It appears to be relatively straight-forward. Some guidance can be found in these links:

  • SO post about overriding Backbone.Sync
  • Blog post about consuming XML services in Backbone
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号