WCF Example (11)

Source: Internet
Author: User

Introduced

WCF (Windows communication Foundation)-session state:

ServiceContract

· Sessionmode.allowed-Specifies that the contract also supports sessions (default) When incoming binding support sessions

· SessionMode.Required-Specifies that the contract requires session binding. If the binding is not configured to support sessions, an exception is thrown

· Sessionmode.notallowed-Specifies that the contract will never support binding to start a session

OperationContract

· IsInitiating-Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server, if a session exists.

· IsTerminating-Gets or sets a value that indicates whether the service operation causes the server to close the session after it sends a reply message, if one exists.

Example

1. Service

IHello.cs

 using System; using System.Collections.Generic; using System.Linq; using System.Text;
  
Using System.ServiceModel; Namespace WCF. servicelib.sessionmanagement {/**////<summary>///interface to demo session state///</summary>notallowed///<remark S>///SessionMode-Gets or sets whether the session///sessionmode.allowed is allowed, disallowed, or required-Specifies that the contract also supports sessions (default)///when an incoming binding support session is available Sessionmode.requi Red-Specifies that the contract requires session binding. If the binding is not configured to support a session, an exception is thrown///sessionmode.notallowed-Specifies that the contract will never support the binding///of the start session </remarks> [ServiceContract (SessionMode = sessionmode.required)] public interface Ihello {/**////<summary>///initialization session///</summary
    >///<remarks>///isinitiating-Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server, if a session exists.
    IsTerminating-Gets or sets a value that indicates whether the service operation causes the server to close the session after it sends a reply message, if one exists.
  
    </remarks> [OperationContract (isinitiating = true, IsTerminating = False)] void startsession ();
/**////<summary>///End Session///</summary>    [OperationContract (isinitiating = False, IsTerminating = true)] void stopsession (); /**////<summary>///Get counter results///</summary>///<returns></returns> [Operationcon
  
    Tract (isinitiating = false, IsTerminating = false)] int Counter (); /**////<summary>///Access SessionID///</summary>///<returns></returns> [operatio
  Ncontract (isinitiating = False, IsTerminating = False)] string GetSessionID (); }
}

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.