1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    21
    Vote Rating
    0
    KeithBurns is on a distinguished road

      0  

    Default Designer 2 POST data to server failing

    Designer 2 POST data to server failing


    Hello,
    I am having trouble in designer 2 Build 311, with adding or updating data to server.

    I have been working through Phil's citybars example and created a project using the concepts discussed.

    Everything is great, am able to load data from server, but have been trying to add or update data with no success. have tried the two following methods.
    This using the store:
    Code:
    var store = Ext.data.StoreManager.lookup('JobsStore');
    store.add({id:'',JobID:'123', JobNumber:'ALD01', JobName:'NewJob'});
    store.sync();
    This using a model with a rest proxy as per the ST 2 examples:
    Code:
    Ext.define('Jobs', {
        extend: 'Ext.data.Model',
                 config: {
            fields: ['id', 'JobID','JobNumber','JobName'],
            proxy: {
                type: 'rest',
                url: '/Maintenance/data/2012/March/'
            }
        }
    });
    var user = Ext.create('Jobs', {id:'',JobID:'123', JobNumber:'ALD01', JobName:'NewJob});
    user.save({
        success: function(user) {
            user.set('JobName', 'Added New Job');
            user.save(); 
        }
    });
    Both of these return the dreaded 405 error from server.
    I have followed the instructions from this thread, with no luck.
    http://www.sencha.com/forum/showthre...ith-JSON/page2

    Originally I was running from our web server and thought it was iis 7 config.
    I then switched to running from localhost using iis 5.1 and get the same error, Have nade all adjustments to iis 5.1 locally and iis7 on server).
    Then I ran on imac as localhost and there is no error returned, however no data is written?

    Now am confused is it server iis setting or is it the way I'm sending request?

    Thank you
    Keith

  2. #2
    Sencha User
    Join Date
    Dec 2011
    Posts
    21
    Vote Rating
    0
    KeithBurns is on a distinguished road

      0  

    Default


    Have managed to get working on localhost iis 5.1, was not configured correctly for json POST.

    The 405 error is no longer and I get a success response but data is not written to the file.

    Do I need to add a jsonwriter to designer?

  3. #3
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,369
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Quote Originally Posted by KeithBurns View Post

    The 405 error is no longer and I get a success response but data is not written to the file.

    Do I need to add a jsonwriter to designer?
    jsonwriter will write back the data as your store changes. However you will need some way of committing those changes back to the file; what server side language are you using to write the data?
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  4. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    21
    Vote Rating
    0
    KeithBurns is on a distinguished road

      0  

    Default


    Sorry Aaron, have been battling to get the iis 7 on SBS 2008 to play nice with json POST.

    Kept following the instructions from this thread,

    http://www.sencha.com/forum/showthre...ith-JSON/page2

    Got it to work on localhost using iis5.1, then tried on windows server 2003 iis 6.0 and with a bit of playing around got it working. SBS 2008 would not work, when the mapped handler json was added as per the instructions, the web.config file in the root directory had the following added under <system.webserver>

    HTML Code:
    <handlers accessPolicy="Read, Script">                  
    <add name="JSON" path=".json" verb="GET,POST" modules="IsapiModule" scriptProcessor="C:\Windows\System32\inetsrv\asp.dll" resourceType="File" preCondition="bitness64"/>
    </handlers>
    Took ages to find this but the "bitness64" was causing the problem, when changed to bitness32 all works as expected.

    Now that is fine I want to use C# web service to receive the synced store data.

    The store.sync() seems to return an updated store object with 3 arrays
    - array of items added
    - array of items deleted
    - array of items updated.

    Am I in the right direction if I pass the relevant array, (depending on what has triggered store sync, add, delete or update), to the webservice and then deserialise into .net object and then write to file?

    OR

    do I wrap the store.sync() in a callback to get the request payload, (assume this would be a json string) and pass this to the webservice to be written to file?

    As you can tell I am new to web development and would appreciate some pointers.

    Thank you

  5. #5
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,369
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Quote Originally Posted by KeithBurns View Post
    Am I in the right direction if I pass the relevant array, (depending on what has triggered store sync, add, delete or update), to the webservice and then deserialise into .net object and then write to file?
    Yes, have you also added/configured a writer to your store/model?
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  6. #6
    Sencha User joostvanhassel's Avatar
    Join Date
    Jan 2012
    Location
    Rotterdam, The Netherlands
    Posts
    102
    Vote Rating
    1
    joostvanhassel is on a distinguished road

      0  

    Default


    I'm having sort of the same setup, with a REST c# backend. I use:
    • a JsonStore
    • a RestProxy
    • a JsonReader
    Calling all operations (select, update, insert, delete) work in this setup, I don't use a JsonWriter.

    As I understand your 405 errors are gone, which probably means you now can log the received data on the serverside am I correct? If not, let me know, I might be able to help you there.

  7. #7
    Sencha User
    Join Date
    Dec 2011
    Posts
    21
    Vote Rating
    0
    KeithBurns is on a distinguished road

      0  

    Default


    Yes I have added a jsonwriter to the proxy on the store in designer, have only set the root property.

    Yes all 405 problems are gone, have been working with both c and vb.net backends.
    I have trialled both working as webservice, currently using vb call which returns logged on user in the init.

    Code:
    Ext.Ajax.request({    url: '/GMsWebSvcVB/Service1.asmx/GetUserLogon',
        method: 'POST',
        jsonData: {},
        success: function (response, opts) {
            var xmlText = Ext.decode(response.responseText);
            console.log(xmlText.d.sUserName);
            console.log(xmlText.d.sDomainName);
           
             Ext.define('userLogon', {
                singleton: true,
                value: xmlText.d.sUserName
            });
        },
        failure: function (response, opts) {
            alert(response.responseText);
        }
    });
    How can I adapt something like this to pass the json data and also need to pass the path to store the json data in?

    Thanks

  8. #8
    Sencha User joostvanhassel's Avatar
    Join Date
    Jan 2012
    Location
    Rotterdam, The Netherlands
    Posts
    102
    Vote Rating
    1
    joostvanhassel is on a distinguished road

      0  

    Default


    What I do on the server side (I'll explain in text and not in code as I use WCF):
    • I set up a webservice that listens a specific url (lets say 'example.com/service'), but only the GET method
      • here i execute code to return data to Sencha
    • I set up a second service that listens to the same url (so again 'example.com/service'), but for another method (say, PUT for an update)
      • here i execute code that processes the update and returns the object to confirm the update
    The key concept here is that all actions (selects, updates, inserts, deletes) will use the same url, but with a different method:
    • select --> GET
    • insert --> POST
    • update --> PUT
    • delete --> DELETE
    Sencha handles this for you on the clientside (by means of the RestProxy), you have to make sure to differentiate by methods on the server side.

    Does this help?

  9. #9
    Sencha User
    Join Date
    Dec 2011
    Posts
    21
    Vote Rating
    0
    KeithBurns is on a distinguished road

      0  

    Default


    AM
    joostvanhassel,

    I am new to web services, I am getting the error below when I try to post to WCF service I get the following

    HTML Code:
    Cannot process the message because the content type 'text/xml' was not the expected type 'application/soap+xml; charset=utf-8'.
    What is happening here?

    Thanks

  10. #10
    Sencha User joostvanhassel's Avatar
    Join Date
    Jan 2012
    Location
    Rotterdam, The Netherlands
    Posts
    102
    Vote Rating
    1
    joostvanhassel is on a distinguished road

      0  

    Default


    Hi Keith,

    It looks like your service is not configured to accept Json. Make sure you set de ResponseFormat and RequestFormat to WebMessageFormat.Json.
    Last edited by joostvanhassel; 2 Apr 2012 at 2:14 AM. Reason: corrected to WebMessageFormat.Json

Thread Participants: 2