I am wanting to expose a restful web service for posting and retrieving data, this may be consumed by mobile devices or a web site.
Now the actual creation of the service isn’t a problem, what does seem to be a problem is communicating from a different domain.
I have made a simple example service deployed on the ASP.NET development server, which just exposes a simple POST action to send a request with JSON content. Then I have created a simple web page using jquery ajax to send some dummy data over, yet I believe I am getting stung with the same origin policy.
Is this a common thing, and how do you get around it? Some places have mentioned having a proxy on the domain that you always request a get to, but then you cannot use it in a restful manner…
So is this a common issue with a simple fix? As there seem to be plenty of restful services out there that allow 3rd parties to use their service…
How exactly are you "getting stung with the same origin policy"? From your description, I don’t see how it could be relevant. If
yourdomain.com/some-path/defined-request.jsonreturns a certain JSON response, then it will return that response regardless of what is requesting the file, unless you have specifically defined required credentials that are not satisfied.Here is an example of such a web service. It will return the same JSON object regardless of from where the request is made: http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true
Unless I am misunderstanding you (in which case you should clarify your actual problem), the same origin policy doesn’t really seem to apply here.
Update Re: Comment
"I make a simple HTML page and load it as
file://myhtmlfilelocation/myhtmlfile.htmland try to make an ajax request"The cause of your problem is that you are using the
file://URL scheme, instead of thehttp://protocol scheme. You can find information about this scheme in Section 3.10 of RFC 1738. Here is an excerpt:You should be able to resolve your issue by using the
http://scheme instead of thefile://scheme when you make your asynchronous HTTP request.