Get the App
SLTechnology News&Howtos  ›  Development  › 

How the WCF service operates SayHello ()

Shulou Source: shulou.com Published: 2022-06-02 06:40:48 09月13日 Update

This article introduces the knowledge of "how WCF Services operate SayHello ()". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Here we define three activation types of service classes: monotonous service (Per-CallService), session service (SessionfulService), singleton service (SingletonService), hosted by the host respectively, here for testing, we use the binding protocol is also TCP, other protocols are not specifically implemented here, interested friends can expand and modify the code for testing.

WCF services support three types of instance activation: monotonous services (Per-Call Service): each client request allocates a new service instance. Similar to Net Remoting's SingleCall pattern; session Service (Sessionful Service): one service instance is assigned to each client connection. Similar to Net Remoting's client activation mode; singleton service (Singleton Service): all clients share the same service instance for all connections and activation objects. Similar to Net Remoting's SingleTon mode.

WCF service: a service contract and an operation SayHello () are defined. The specific WCF service type definition and activation type configuration are as follows:

/ / this example defines a service contract. The three services are monotonous service, session service, singleton service or singleton service namespaceWCFService {/ / 1. Service contract [ServiceContract (SessionModeSessionMode=SessionMode.Allowed,Namespace= "http://www.cnblogs.com/frank_xl/")] publicinterfaceIWCFService {/ / Operation contract [OperationContract] voidSayHello ();} / / 2. Service category. Monotone service [ServiceBehavior (InstanceContextModeInstanceContextMode=InstanceContextMode.PerCall)] publicclassWCFServicePerCall:IWCFService,IDisposable {/ / Service instance count privateintmCcount=0; / / Constructor publicWCFServicePerCall () {Console.WriteLine ("WCFServicePerCallInstanceisCreated");} / implement the method publicvoidSayHello () {mCcount++; Console.WriteLine ("WCFServicePerCallInstanceCountis: {0}", mCcount);} / / implement the method Dispose publicvoidDispose () {Console.WriteLine ("WCFServicePerCallInstanceisdisposed") defined by the interface }} / / 3. Service category. Session service [ServiceBehavior (InstanceContextModeInstanceContextMode=InstanceContextMode.PerSession)] publicclassWCFServicePerSession:IWCFService {/ / Service instance count privateintmCcount=0; / / Constructor publicWCFServicePerSession () {Console.WriteLine ("WCFServicePerSessionInstanceisCreated");} / / implement the interface definition method publicvoidSayHello () {mCcount++; Console.WriteLine ("WCFServicePerSessionInstanceCountis: {0}", mCcount);} / / implement the interface definition method Dispose publicvoidDispose () {Console.WriteLine ("WCFServicePerSessionInstanceisdisposed");}} / / 4. Service category. Singleton service [ServiceBehavior (InstanceContextModeInstanceContextMode=InstanceContextMode.Single)] publicclassWCFServiceSingleTon:IWCFService {/ / Service instance count privateintmCcount=0; / / Constructor publicWCFServiceSingleTon () {Console.WriteLine ("WCFServiceSingleTonInstanceisCreated");} / implement the method publicvoidSayHello () {mCcount++; Console.WriteLine ("WCFServiceSingleTonInstanceCountis: {0}", mCcount);} / / implement the method Dispose publicvoidDispose () {Console.WriteLine ("WCFServiceSingleTonInstanceisdisposed") defined by the interface That's all for "how WCF Services operate SayHello ()". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Services instances interfaces methods activation monotony contracts customers clients types functions patterns content more knowledge distribution hosting testing utility same Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi MariaDB Docker NVidia