1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Porto, Portugal
    Posts
    31
    Vote Rating
    0
    Nunoestrada is on a distinguished road

      0  

    Default Unanswered: Access wcf rest webservice with JSON

    Unanswered: Access wcf rest webservice with JSON


    Hello,

    I am trying to use sencha to access a wcf webservice that receives and returns JSON format data. (Cross domain)

    I am having the following message in the browser inspector:

    OPTIONS
    http://"link to the resource" 200 (OK)

    XMLHttpRequest cannot load http://"link to the resource" Origin http://localhost:81 is not allowed by Access-Control-Allow-Origin.

    I have tried many things so far. I tryed to "bypassed" the security using this:
    Code:
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "x-requested-with");
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type");

    My code for the call is the following:
    Code:
            Ext.Ajax.request({
                url: "http://link to the resource",
                method: "POST",
                params: {
                    rData: JSON.stringify({
                    CompanyDb: "Company",
                    PatientID: "100"    
                    })
                },
                //withCredentials: true,
                useDefautXhrHeader: false,
                success:function(resp){
                    var obj = JSON.decode(resp.reponseText);
                    alert(obj);
                },
                failure:function(resp){ alert("ERRO: " + resp.reponseText);},
                headers:{
                    "Content-type": "application/json; charset=utf-8"
                }
                
            });
    I have commented the withCredentials line because it would give me this error: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.

    What am I doing wrong?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,735
    Answers
    3364
    Vote Rating
    756
    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


    Are you trying to use CORS?
    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.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Porto, Portugal
    Posts
    31
    Vote Rating
    0
    Nunoestrada is on a distinguished road

      0  

    Default


    yes

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,735
    Answers
    3364
    Vote Rating
    756
    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


    If you are going to use withCredentials then the "Access-Control-Allow-Origin header needs to be something more than the wildcard '*' like the domain
    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.

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Location
    Porto, Portugal
    Posts
    31
    Vote Rating
    0
    Nunoestrada is on a distinguished road

      0  

    Default


    I am only using the withCredentials because I saw that in this guide: http://docs.sencha.com/touch/2-0/#!/guide/ajax in th section Cross Domain Requests, But I don't need to use the credentials for any reason.

    All I wanted was to be able to call the wcf webservice properly

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

      0  

    Default


    [works, but bad practise]
    Are you going to deploy your application as an standalone app on a device and are you using your browser just for testing purposes? In that case you can start Chrome with an extra parameter --disable-web-security so there are no issues with cross domain scripting.
    You could do this by creating a shortcut to Chrome and append the parameter to the shortcuts target.

    Do not use a browser started this way to browse the internet, as it is not secure! Use at own risk!
    [/works, but bad practise]


    edit your web.config to include the following:
    Code:
      <system.webServer>
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="YourDomainHere" />
          </customHeaders>
        </httpProtocol>
      </system.webServer>
    replace YourDomainHere with your domain, ip, localhost or *
    Last edited by joostvanhassel; 28 Mar 2012 at 11:29 AM. Reason: added better solution

  7. #7
    Sencha User
    Join Date
    Mar 2009
    Posts
    227
    Answers
    1
    Vote Rating
    0
    SchattenMann is an unknown quantity at this point

      0  

    Default


    Quote Originally Posted by joostvanhassel View Post
    [works, but bad practise]
    Are you going to deploy your application as an standalone app on a device and are you using your browser just for testing purposes?
    Once the application deployed how one should proceed?

    I won't be able to know the ip of every mobile phone using it...or am i missing something?

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

      0  

    Default


    Quote Originally Posted by SchattenMann View Post
    Once the application deployed how one should proceed?

    I won't be able to know the ip of every mobile phone using it...or am i missing something?
    Are you trying to use CORS and withCredentials? Or are you simply trying to fetch some JSON?

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar