I suppose you could do this by starting a new Thread as soon as the WCF operation starts. The real work then happens on the new thread and the original WCF request thread waits using a Thread.Join() with a specific timeout. If the timeout occurs the worker thread can be canceled using a Thread.Abort().
Something like this:
public string GetData(int value)
{
string result = "";
var worker = new Thread((state) =>
{
// Simulate l0ng running
Thread.Sleep(TimeSpan.FromSeconds(value));
result = string.Format("You entered: {0}", value);
});
worker.Start();
if (!worker.Join(TimeSpan.FromSeconds(5)))
{
worker.Abort();
throw new FaultException("Work took to long.");
}
return result;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…