can ASP.NET redirect an ajax call to a different web service?
We have AJAX scripts to help "collecting" the data for rendering our web pages. Some of the data will be coming from a different web service. Now the browser doesn't allow us to make AJAX calls directly to another web service (must match schema, host and port). One way to work around it is to have AJAX call local web service (or something like that) which then redirect the calls to another web service. Is this doable on ASP.NET? someone mentioned virtual directory, but I didn't开发者_运维知识库 find any samples on that.
Sure, this is called a proxy (or if you're using JSON, it can be JSONP), and it's platform independent.
Here's how it works:
- Browser makes an Ajax request to somewhere the same domain that you control, such as /AjaxProxy.aspx
- You have an ASP.NET page at AjaxProxy.aspx that makes a call out to the web service with some parameters
- AjaxProxy.aspx spits out the results of the web service call to Response.Output (or however else you choose to display it on the page)
- Browser receives those contents and you can work with it just like you'd made a call to the actual web service.
Yes. A scenario would be like this:
- Browser calls the web service on ASP.NET via AJAX
- ASP.NET calls another web service (via JSON/XML...etc)
- ASP.NET parses the response and then response to the browser
This is a simple example of how to consume another web service in ASP.NET: http://www.asp.net/general/videos/how-do-i-create-and-call-a-simple-web-service-in-aspnet
精彩评论