0

Possible Duplicate:
WCF Windows Service - Long operations/Callback to calling module

I have a WCF application hosted on windows service. I have to use basicHttpBinding. In the application, I make a long-term analysis of the data, and then turn them into customers.

Is it possible to call WCF creating a thread that will be carried out analysis (Id of this thread will be sent to the client)?

The client should be able to communicate with the theme of using the transmitted ID and, if it receives information that the data is ready, it should be able to be downloaded. This will, in turn, release the thread.

How can I achieve this functionality?

Ok. It works. Client method call creates a thread that even after paying guid runs in the background and saves the result of the operation. How best can store these results? Due to the fact that the service is running Per Call dictionary resets with each calling the service. Declaring static data can be overridden, but I do not think it was a good idea. Any ideas?

namespace WCFRiskService
{
    [ServiceContract]
    public interface IRiskService
    {
        // return Thread ID
        [OperationContract]
        int GetAnalysis(AnalysisId);

        [OperationContract]
        string GetAnalysisData(int ThreadId);
    }

    public class Analysis
    {
        public GenerateAnalysis()
        {
            Thread.Sleep(20000);
            Analysis = "Generated Data";
        }
    }

    public class RiskService : IRiskService
    {
        // How can I change this, to use non-static objects ?
        static string AnalysisData = "";

        public string GetAnalysisData(int ThreadId);
        {
            return AnalysisData;
        }

        public int GetAnalysis(AnalysisId);
        {
            Analysis AObject = new Analysis();
            AObject.Tree = AnalysisTree;
            Thread workerThread = new Thread(AObject.GenerateAnalysis);
            int managedThreadId = workerThread.ManagedThreadId;

            workerThread.Start();
            while (!workerThread.IsAlive) ;

            return managedThreadId;
        }
    }
}
Community
  • 1
  • 1
Emil J
  • 215
  • 2
  • 4
  • 20
  • I do not know how to go about it. I'd just like to WCF application that uses basicHttpBinding, to benefit from the threads common to all requests for the service and if necessary, terminate a thread. – Emil J Nov 15 '12 at 13:54

1 Answers1

0

You could create a job Id (Guid) for each job and pass it back to the client. Then in the service, store the job Id on a ConcurrentDictionary<Guid, AnalysisResult> and when the client asks for the results, you return the AnalysisResult that corresponds to the job Id. The client will need to check if the AnalysisResult that is returned by the operation is not null and etc.

Note that polling is not the best approach though.

If you could replace basicHttpBinding with wsDualHttpBinding then have a look at the duplex services that allow both endpoints to send messages. This way the server can send messages to the client anytime it wishes to. You could created a callback interface for progress reporting.

Panos Rontogiannis
  • 4,154
  • 1
  • 24
  • 29