• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

asp.net cross domain web services/ wcf

I have created a simple wcf / c# web service and have cross domain issue.
And I understood that can be resolved by written codes in Jquery or change browser setting.
Is it any possibility to write codes inside of WCF codes to fix the issue?
0
ITsolutionWizard
Asked:
ITsolutionWizard
  • 2
1 Solution
 
OriNetworksCommented:
Can you give an example of the code you are using and what error you are receiving?
0
 
ITsolutionWizardAuthor Commented:
I have below codes with cross domain issue in Chrome and Firefox.
And I did install below links from Chrome but still not working.

However, IE working with enable the cross domain under Internet Option >> Security Tab

Any ideas

function GetModelList(divisCode)
      var customerNo = "315217";            
        var GetModelListJSon = "http://clientaccesstest.abc/GetModel";            
        $(document).ready(function () {
            $.ajax({
                cache: false,
                type: "GET",
                async: false,
                dataType: "json",
                contentType: 'text/plain',
                url: GetModelListJSon + encodeURIComponent("(011,115217)"),
                success: function (data) {
                    $('#data').html(data);
                    if (data == null)
                        return;
                    resultObj = jQuery.parseJSON(data);
                    if (resultObj.Status != 'Failed') {
                        $('#json').html(setModelInfo(resultObj.Data,divisCode));
                    }
                },
                error: function (xhr,status,error) {
                    $('#data').html(xhr.responseText);
                    alert(xhr.responseText + " : error GetModelListJSon");
alert(status);
alert(error);
                }
            });
        });
}


https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
https://chrome.google.com/webstore/detail/forcecors/oajaiobpeddomajelicdlnkeegnepbin/related?hl=en

http://codedevstuff.blogspot.com/2014/10/use-chrome-for-development-and-allow.html
0
 
toakkiyadavCommented:
Hi,

I'm not sure how you will consume in WCF but for Web, there is package you can use it.
Alternatively below code also works:

HttpResponseMessage msg;

msg.Headers.Add("Access-Control-Allow-Origin", "*");
msg.Headers.Add("Access-Control-Allow-Credentials", true.ToString());
msg.Headers.Add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
 msg.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, Location");
msg.Headers.Add("Access-Control-Expose-Headers", "Location");

HTH
0
 
ITsolutionWizardAuthor Commented:
toakkiyadavm thank you for your codes samples. Actually, I already posted my codes. How should I merge yours to mine?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now