Question

I (new to WCF) am writing a WCF service that acquires and analyzes an X-ray spectrum - i.e. it is a long-running process, sometimes several minutes. Naturally, this begs for asynchronous calls so, using wsDualHttpBinding and defining the following in my ServiceContract

   [ServiceContract(Namespace="--removed--",
    SessionMode=SessionMode.Required, CallbackContract=typeof(IAnalysisSubscriber))]
public interface IAnalysisController 
{
    // Simplified - removed other declarations for clarity
    [OperationContract]
    Task<Measurement> StartMeasurement(MeasurementRequest request);
}

And the (simplified) implementation has

    async public Task<Measurement> StartMeasurement(MeasurementRequest request)
    {
        m_meas = m_config.GetMeasurement(request);
        Spectrum sp = await m_mca.Acquire(m_meas.AcquisitionTime, null);
        UpdateSpectrum(m_meas, sp);
        return m_meas;
    }


private void McaProgress(Spectrum sp)
{
   m_client.ReportProgress(sp);
}

Where m_client is the callback object obtained from m_client = OperationContext.Current.GetCallbackChannel(); in the "Connect" method - called when the WCF client first connects. This works as long as I don't use progress reporting, but as soon as I add progress reporting by changing the "null" in the m_mca.Acquire() method to "new Progress(McaProgress)", on the first progress report, the client generates an error "The server did not provide a meaningful reply; this might be caused by a contract mismatch..."

I understand the client is probably awaiting a particular reply of a Task rather than having a callback made into it, but how do I implement this type of progress reporting with WCF? I would like the client to be able to see the live spectrum as it is generated and get an estimate of the time remaining to complete the spectrum acquisition. Any help or pointers to where someone has implemented this type of progress reporting with WCF is much appreciated (I've been searching but find mostly references to EAP or APM and WCF and not much related to TAP).

Thanks, Dave

Was it helpful?

Solution

Progress<T> wasn't really meant for use in WCF. It was designed for UI apps, and may behave oddly depending on your host (e.g., ASP.NET vs self-hosted).

I would recommend writing a simple IProgress<T> implementation that just called IAnalysisSubscriber.ReportProgress directly. Also make sure that IAnalysisSubscriber.ReportProgress has OperationContract.IsOneWay set to true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top