WCF Server Timeout

Is there a way to tell the WCF service the response to the request (with or without cancellation of its processing) after a certain time, even if it has not yet completed, something like a timeout policy on the server side?

+3
source share
4 answers

I suppose you could do this by starting a new topic as soon as the WCF operation starts. The real work then happens in a new thread, and the original WCF request stream expects to use Thread.Join () with a specific timeout. If a timeout occurs, the workflow can be canceled using Thread.Abort ().

Something like that:

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;
}
+2
source

I solved the same problem and created a blog post:

http://kanchengcao.blogspot.com/2012/06/adding-timeout-and-congestion.html

:

  • - WCF .
  • , .
  • - , .

, , , , -.

+1

, - , , , , .

, - Windows, , WCF MSMQ. - . , -. .

0

, , .

, - , , . WCF ,

BeginFoo( fooParam1, fooParam2, AsyncCallback callback, object state)

/ EndFoo().

, , .

wcf, , -, .

In addition, you should try to use a client that supports timeout or cancellation requests because you cannot rely on the server to request a request from you. Perhaps there is no connectivity, or another problem may occur on the server.

Cheers, Chris

0
source

Source: https://habr.com/ru/post/1712979/


All Articles