Closure of service agents and limitations of concurrent sessions

Source: Internet
Author: User

These days the bindings for WCF were replaced by BasicHttpBinding with Wshttpbinding, and then the problem was accompanied by wshttpbinding bindings.

Sometimes the client gets an exception: the request channel waits for 00:00:59.9840000 after the reply time-out. Increase the time-out value passed to the request call, or increase the sendtimeout on the binding. The time allotted to this operation may be part of a longer time-out . Resume normal after service restart.

Read a related article in the Artech blog: http://www.cnblogs.com/artech/archive/2009/07/04/1516908.html

Tidy up as follows:

1. The channel is divided into two kinds

    • Session channel (Sessionful Channel): The session channel ensures that messages transmitted between the client and the server can be correlated, but the channel error (FAULT) affects subsequent message exchanges;
    • Datagram Channels (Datagram Channel): Even in the same datagram channel, each message is exchanged independently, and channel errors do not affect subsequent message exchanges

2. Channel creation

For most binding types (except BasicHttpBinding), the session channel is created by default. For WCF clients, if you make a service call based on a session channel, there are some issues that need to be given enough attention (based on the first problem that the session channel service invocation needs to be aware of and WCF traffic throttling), and if used improperly, affects not only the service invocation of the client itself, It also has a significant impact on the throughput of service processing requests.

The following is the code for the client to invoke the service:

1 class Program2     {3         Static voidMain (string[] args)4         {5             Try6             {7                  for(inti =0; I <10000; i++)//Loop 10,000 call service8                 {9SR. TestClient C =NewSR. TestClient ();Ten                         stringres = C.login ("Zhang San","123","",""); OneConsole.WriteLine ("""+ i +"""); A                 } -             } -             Catch(Exception ex) the             { - Console.WriteLine (ex. Message); -             } - console.readline (); +         } -}

Execution Result:

This behavior occurs because the service proxy is not closed after the client invokes the service. The number of connections exceeds WCF's control over the number of concurrent sessions.

Wshttpbinding security Mode (SECURITYMODE) is message-based security by default, so the created channel is automatically given the session's characteristics.

This problem does not occur before BasicHttpBinding binding mode because BasicHttpBinding is not a session mode

The client calls use the following pattern instead

1 class Program2     {3         Static voidMain (string[] args)4         {5             Try6             {7                  for(inti =0; I <10000; i++)8                 {9SR. TestClient C =NewSR. TestClient ();Ten                     stringres = C.login ("Zhang San","123","",""); OneConsole.WriteLine ("""+ i +"""); A c.close (); -                     //---------------------or----------- -                     //using (SR. TestClient C = new SR. TestClient ()) the                     //{ -                     //string res = C.login ("Zhang San", "123", "", ""); -                     //Console.WriteLine ("" "+ i +" ""); -                     //} +                 } -             } +             Catch(Exception ex) A             { at Console.WriteLine (ex. Message); -             } - console.readline (); -         } -}

Closure of service agents and limitations of concurrent sessions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.