WCF

R4R® WCF with C# WCF Tutorials
(追記) (追記ここまで)
(追記) (追記ここまで)
Per-Session Services

Per service endpoint per proxy is the client session.

If the client creates another proxy to the same or a different endpoint then that second proxy will be associated with a new instance and session.

Configuring Private Sessions:

A session has three elements

  1. behavior,
  2. binding,
  3. contract.
(追記) (追記ここまで)

The behavior part is used for that WCF will keep the service instance alive throughout the session and to direct the client messages to it.

This local behavior is created by setting the InstanceContextMode property of the ServiceBehavior attribute to InstanceContextMode.PerSession:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
class MyService : IMyContract
{...}

Since InstanceContextMode.PerSession is the default value of the InstanceContextMode property, these definitions are equivalent:

class MyService : IMyContract
{...}
[ServiceBehavior]
class MyService : IMyContract
{...}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
class MyService : IMyContract
{...}
SessionMode.Allowed

SessionMode.Allowed is the default value of the property, so these definitions are equivalent:

[ServiceContract]
interface IMyContract
{...}
[ServiceContract(SessionMode = SessionMode.Allowed)]
interface IMyContract
{...}

Example Per-session service and client

///////////////////////// Service code /////////////////////
[ServiceContract(SessionMode = SessionMode.Required)]
interface IMyContract
{
[OperationContract]
void operation( );
}
class MyService : IMyContract,IDisposable
{
int flag= 0;
MyService( )
{
Trace.WriteLine("MyService.MyService( )");
}
public void operation( )
{
flag++;
Trace.WriteLine("Counter = " + flag);
}
public void Dispose( )
{
Trace.WriteLine("MyService.Dispose( )");
}
}
///////////////////////// Client code /////////////////////
MyContractClient proxy = new MyContractClient( );
proxy.operation( );
proxy.operation( );
proxy.Close( );
//Output
MyService.MyService( )
Counter = 1
Counter = 2
MyService.Dispose( )
(追記) (追記ここまで)
Hot Topics

Database & SQL

HR FAQs

Interview & FAQs

ASK Questions

PHP

Testing

More Links

Tutorials

Articles

Source Code

e-Books

Certifications

FAQS

Copyright ©2021-22 r4r.co.in, all rights reserved. Theguestspost.com
Sitemap
Career
Post comment
About us
Subscription
Unsubscription

AltStyle によって変換されたページ (->オリジナル) /