0

I am working on WCF project hosted by asp.net/IIS. This WCF service has a Method called SearchImage, which looks like this:

string SearchImage(string query)
{
  //call bing service to get the images
  //it is very time-consuming
  return result.
}

The call to bing service is very time consuming. This can impact the service very much. Async call doesn't help here:

string SearchImage(string query)
{
  //async call bing service to get the images
  WaitForComplete();
  return result.
}

You can see, I still need to wait until bing returns result.

My question is, is there any technology to avoid this kind of block IO issue? Ideally, I want to tell asp.net to response when bing result is back.

  • Can you look at it from the other way around? Initiate AJAX on the webpage, and the AJAX handler then calls the WCF? That way the user get an immediate response from the website, and the WCF can take all the time it needs – freefaller Jun 29 '12 at 09:16

2 Answers2

0

No. What you have to do is return a complete web page, with javascript embedded (jquery is popular, though atlas can integrate with asp.net better) that will perform the async call after the page is already rendered, and then replace the relevant DOM section (usually tagged with a CSS id) with the contents that you loaded. That way, the user sees everything loaded but a throbber, which will be replaced by the final text, image, or whatever you're loading once it's ready.

You can make the async call go to your server, so that you can do the extra massaging server-side, but that's rarely worth the effort. Javascript can handle almost any massaging you need.

SilverbackNet
  • 2,076
  • 17
  • 29
  • But it is a pure data service, no javascript/web page involved here. So there is no way to avoid block IO? – XU Weijiang Jun 29 '12 at 09:29
  • I'm not sure exactly what you mean, but if it's anything like web services, no, there's usually no way you can return partial results and then turn around and return more once the IO completes. Depends on the API, of course, but it looks like you're out of luck. – SilverbackNet Jun 29 '12 at 09:32
  • I see. Thanks, It seems I need to live with it. :-) – XU Weijiang Jun 29 '12 at 12:34
0

I once worked on a project where I needed to parse the website structure by recursively navigating to all internal links. I used a plain ASP.NET application as a frontend and a WCF service (don't remember if it was hosted in IIS or as a Windows service) which does the actual job.

Since the process of traversing all links can take a long time to complete (plus I needed to inform the user with the progress periodically) I implemented an asynchronous service operation (MSDN reference) for performing an actual parsing (was called server-side) and a synchronous one for pooling the status of the task (was periodically called client-side using AJAX).

This SO question contains some useful links regarding the subject: How to make a call to my WCF service asynchronous?

Hope this will help you a bit.

Community
  • 1
  • 1
volpav
  • 5,090
  • 19
  • 27