开发者

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:

  1. Browser makes an Ajax request to somewhere the same domain that you control, such as /AjaxProxy.aspx
  2. You have an ASP.NET page at AjaxProxy.aspx that makes a call out to the web service with some parameters
  3. 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)
  4. 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:

  1. Browser calls the web service on ASP.NET via AJAX
  2. ASP.NET calls another web service (via JSON/XML...etc)
  3. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜