Calling external web service on different thread from web service

This is current functionality:

  • My web site calls my ASP.NET Web Service synchronously.
  • My web service creates a record in the database.
  • My web service returns new record id to the web site immediately.
  • My web site displays that record id to user.
  • This has been working fine. I have to add a feature so that after step 2, my web service will call 1 to 6 (depending upon condition) external web services. So it would look like this:

  • My web site calls my ASP.NET Web Service synchronously.
  • My web service creates a record in database.
  • My web service calls external web services. Merges results and saves in the database.
  • My web service returns new record id to the web site.
  • My web site displays that record id to user.
  • Now web site request could take 10 minutes because of this new feature. So this is how I would like to implement new feature.

  • My web site calls my ASP.NET Web Service synchronously.
  • My web service creates a record in database.
  • My web service creates a new thread and calls a method on that thread (fire and forget). This method will call external web services, merge results and save in database. As this will be on another thread, execution will go to step 4 immediately before completing step 3.
  • My web service returns new record id to the web site immediately.
  • My web site displays that record id to user.
  • Also, I would like set some timeout for the thread created in step 3 so that the task must end in let's say 10 minutes and if not abort the thread.

    I tried ThreadPool.QueueUserWorkItem which does not even get called as it is background thread. Initially Thread / Task.TaskFactory seem doable but creating a new thread for each request does not seem best practice.

    Can someone provide some VB.NET code / reference for the step 3? Specifically calling external web service on a separate thread something like fire and forget and setting timeout for that thread?

    Thanks


    closeTimeout="04:01:00"
         openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
         allowCookies="false" bypassProxyOnLocal="false"
         hostNameComparisonMode="StrongWildcard"
         maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
         maxReceivedMessageSize="2147483647"
         messageEncoding="Text" textEncoding="utf-8"
         transferMode="StreamedResponse"
         useDefaultWebProxy="true"
    

    try this in your binding properties. It helps to increase timeout period and handle large datas(mb)

    链接地址: http://www.djcxy.com/p/12926.html

    上一篇: iOS中关于轮询web服务有关任务完成的最佳实践

    下一篇: 在Web服务的不同线程上调用外部Web服务