1. #1
    Touch Premium Member
    Join Date
    Jan 2012
    Posts
    17
    Vote Rating
    0
    Answers
    2
    lrobins is on a distinguished road

      0  

    Default Answered: Store proxy calling asp.net asmx webservice

    Answered: Store proxy calling asp.net asmx webservice


    The following code works to call a .net webservice

    Code:
    Ext.Ajax.request({
                headers: {
                    'Content-Type': 'application/json; charset=utf-8'
                },
                method: 'POST',
                url: 'Services.asmx/MyWebservice',
                success: function (response) {
                    //load my store with json formatted data returned in response.responseText
                }
            });
    The following code uses a store proxy to call the same .net webservice, but does not work

    Code:
    var theStore = Ext.create('Ext.data.Store', {
                model: 'App.model.RequestNotesItem',           
                proxy: {
                    type: 'ajax',
                    url: 'Services.asmx/MyWebService',
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    },
                    actionMethods: {
                        create: 'POST',
                        read: 'POST',
                        update: 'POST',
                        destroy: 'POST'
                    }
                }
            });
            theStore.load();
    Does anyone have experience/success in calling an asp.net webservice using the proxy on a store?

  2. What does the JSON look like? Do you need to configure the reader?

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,651
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What does the JSON look like? Do you need to configure the reader?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Touch Premium Member
    Join Date
    Jan 2012
    Posts
    17
    Vote Rating
    0
    Answers
    2
    lrobins is on a distinguished road

      0  

    Default


    I had to add these to the proxy to make it return json successfully

    Code:
    reader: {
             type: 'json',
             root: 'd'
    },
    writer: {
            encodeRequest: true,
            type: 'json'
    }
    Here is a sample of the json returned.

    {"d":"[{\"note_id\":165,\"added_date\":\"2/16/2012 5:03:16 PM\",\"added_by_name\":\"Person1\",\"note_text\":\"and yet another\"},{\"note_id\":164,\"added_date\":\"2/16/2012 5:01:42 PM\",\"added_by_name\":\"Person2\",\"note_text\":\"aabc dd eff lorem ipsum\"}]"}

    .net wraps it in a "d" for security reasons.

    **UPDATE**
    This thread got mistakenly marked as answered, but it's not answered. I wasn't sure how to set it back. I'm getting a json response, but it isn't loading the store correctly.

  5. #4
    Touch Premium Member
    Join Date
    Jan 2012
    Posts
    17
    Vote Rating
    0
    Answers
    2
    lrobins is on a distinguished road

      0  

    Default


    I found my problem. The asp.net asmx service I was using to return json was returning a json string. So it looks like the proxy reader cannot read that json string. I changed to a asp.net wcf service and return a json object through a Stream instead of returning a string (found a bunch of examples of this on google). The store loads the data correctly this way. Hope this helps some fellow asp.net people.

Thread Participants: 1

Tags for this Thread