1. #1
    Sencha User
    Join Date
    Jun 2013
    Posts
    59
    Answers
    1
    Vote Rating
    3
    good_c_ryan_19 is on a distinguished road

      0  

    Default Answered: How to implement WCF Service Rest in Store proxy

    Answered: How to implement WCF Service Rest in Store proxy


    Hi, i started to study Sencha Touch 2 where we will be using this for our first Mobile Application.

    For my mini project i will be creating CRUD ST2 application with using WCF Rest as server side.

    On Read: Im trying to get json result from wcf rest and i need to diplay it on a list but when i run the app it throws :

    Code:
    XMLHttpRequest cannot load http://localhost:12345/Model/Services.svc/GetItem/345?_dc=1372239560510&page=1&start=0&limit=25. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
    On $.ajax call i just add crossDomain: true property.

    How to handle Cross Domain in ST2 and implement it on store?

    Below is my Store Code:

    Store :
    Code:
    Ext.define("Mobile.store.LookupStore", {
        extend: "Ext.data.Store",
        requires: ["Mobile.model.LookupModel"],
        config: {
                model: "Mobile.model.LookupModel", 
                proxy:
                {
                    type: 'ajax',
                    headers: { 'content-type': 'application/json' },
                    url: 'http://localhost:12345/Model/Services.svc/GetItem/345',
                    reader:
                    {
                        type:'json',
                        rootProperty:'GetList',
                    }
                },
                //data:
                //[
                //    { LookupID: 1, LookupName: 'Ryan', LookupDescription: 'Desc1' },
                //     { LookupID: 2, LookupName: 'Ryan2', LookupDescription: 'Desc2' }
                //],
                autoLoad: true
          }
    
    
    });
    I really need help to keep me moving forward in Sencha Touch 2.

    Thanks and Regards

  2. Probably you will need make some changes on your server side http://enable-cors.org/

    It seems like you are running your WFC service using a virtual VS server (because the port).
    Other option is running it on the 8080 port in order to make it available by http://localhost/Model/Services.svc/GetItem/345?_dc=1372239560510&page=1&start=0&limit=25
    run your sencha app also locally and then you won't have problems with your different "domains".



  3. #2
    Sencha User Diego Garcia's Avatar
    Join Date
    Jan 2012
    Location
    San José, Costa Rica.
    Posts
    85
    Answers
    13
    Vote Rating
    7
    Diego Garcia is on a distinguished road

      0  

    Default


    Probably you will need make some changes on your server side http://enable-cors.org/

    It seems like you are running your WFC service using a virtual VS server (because the port).
    Other option is running it on the 8080 port in order to make it available by http://localhost/Model/Services.svc/GetItem/345?_dc=1372239560510&page=1&start=0&limit=25
    run your sencha app also locally and then you won't have problems with your different "domains".


    We are a community, let's behave like that.

  4. #3
    Sencha User
    Join Date
    Jun 2013
    Posts
    59
    Answers
    1
    Vote Rating
    3
    good_c_ryan_19 is on a distinguished road

      0  

    Default


    Thanks Diego. I got this working using below code to my WCF Global Asax.

    Code:
     private void EnableCrossDomainAjaxCall()        {
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    
    
                if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
                {
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                    HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
                    HttpContext.Current.Response.End();
                }
            }
    But i have a new problem with passing parameters. I will create new thread for this issue.

    Thanks and Regards
    Last edited by good_c_ryan_19; 26 Jun 2013 at 6:29 PM. Reason: add new line

Thread Participants: 1

Tags for this Thread