2

I've created a WCF Web Service and I want to access it straight from my html page using JavaScript. However I'm getting a cross-site scripting error.
Here's the error message:

XMLHttpRequest cannot load http://localhost:2875/MyWebService.svc/MyFunction. Origin http://TheCallingServer is not allowed by Access-Control-Allow-Origin.

I've found examples online describing how to do this from an aspx.net page, but I can't find anything about doing this from JavaScript in a HTML page.

What do I have to change in my WCF WebService to allow it to be called from JavaScript?

1
  • You have to put it on the same server/domain. Commented Oct 18, 2012 at 16:24

1 Answer 1

4

The problem is not in your service, is the browser who refuse to call an url in another domain. One solution is to have both, the page and the service under the same domain/site.

Another solution would be to use jsonp: http://www.codeproject.com/Articles/425702/Consume-WCF-Service-with-JSONP-and-SOAP-endpoints

Sign up to request clarification or add additional context in comments.

1 Comment

the problem with the link is that it shows how to call the WCF service from an aspx.net page. I don't have an aspx.net page, I only have a html page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.