1

I need to call a cross domain web service (.asmx) via a page within an asp.net application. The user will type in a search query in which the app will send off to the web service, then the page will be updated with the data.

My question is how might I do this without postbacks? As I am just trying to retrieve data rather than entering or manipulating it.

My attempted solutions:
1. Ajax via jquery -> issue: CORS is not supported.
2. serviceReference (for client side services calls) but this is only for a local (on domain) service
3. Lastly I am trying to use updatepanel where the value from a textbox is used in querying the web service however this is obviously forcing a partial postback, is there a way to have the update panel use a get req instead? If not, how might I go about doing this because I am stuck! Lastly would this solution be easier if an ASP MVC structure? I am learning. Thanks.

user3311351
  • 301
  • 1
  • 2
  • 9
  • Pretty sure .asmx web services only allow Posts (which btw is very different from a Post Back in .net). So you can do a Post via jQuery. – Philip Pittle Jul 21 '14 at 12:31
  • 1
    Either have the page do an updatepanel post, or call a pagemethod or service, which will then invoke an external service. Services across domains is fine to do from the server. – Brian Mains Jul 21 '14 at 12:34
  • @PhilipPittle tried but I was having issues with the cross-origin resource sharing as it is not supported, which was very frustrating. – user3311351 Jul 21 '14 at 12:36
  • 1
    @user3311351 - Yes, javascript can complain if you try to work with services in a different domain. The solution is to create a proxy on your local server that will call the other domain. – Philip Pittle Jul 21 '14 at 12:37

1 Answers1

4

Create an ashx handler which queries the remote service based on parameters handed by ajax.
Use an ajax-request to the ashx handler to call your proxy via jQuery AJAX.

Or just use the Yahoo YQL proxy:
Is there a free JSON proxy server which supports CORS or JSONP?

Or if the web-service supports JSONP, you can use JSONP directly.

If you need to create a proxy yourself, here is how:
http://www.codeproject.com/Articles/25218/Fast-Scalable-Streaming-AJAX-Proxy-continuously-de

Community
  • 1
  • 1
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442