Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How the WCF service operates SayHello ()

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report