In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use WCF interface", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to use WCF interface" this article bar.
WCF provides four types of behavior: service behavior, endpoint behavior, contract behavior, and action behavior. These four behaviors define four WCF interfaces: IServiceBehavior, IEndpointBehavior, IContractBehavior, and IOperationBehavior.
There are four different WCF interfaces, but their interface methods are basically the same: AddBindingParameters(), ApplyClientBehavior(), and ApplyDispatchBehavior(). Note that IServiceBehavior does not include ApplyClientBehavior() methods because it can only work on the server side. We can define our own classes to implement these WCF interfaces, but there are a few caveats:
1. The scope of action of behavior can be expressed in the following table:
2. Extended service behaviors, contract behaviors, and operation behaviors can be added by using custom features, but endpoint behaviors cannot be added; extended service behaviors and endpoint behaviors can be added by using configuration files, but contract behaviors and operation behaviors cannot be added. However, these extended behaviors can be added via ServiceDescription.
Attributing behavior means that when we define our own extended behavior, we can derive it from the Attribute class and add it as an attribute. For example:
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)] publicclassMyServiceBehavior:Attribute,IServiceBehavior... [MyServiceBehavior] publicinterfaceIService...
If you add behavior as a configuration file, you must define a class that inherits from BehaviorExtensionElement (which belongs to the namespace System.ServiceModel.Configuration), and then override the BehaviorType attribute and CreateBehavior() method. The BehaviorType property returns the type of the extended behavior, while the CreateBehavior() method is responsible for creating an object instance of the extended behavior:
publicclassMyBehaviorExtensionElement:BehaviorExtensionElement { publicMyBehaviorExtensionElement(){} publicoverrideTypeBehaviorType { get{returntypeof(MyServiceBehavior);} } protectedoverrideobjectCreateBehavior() { returnnewMyServiceBehavior(); } }
If the configured Element adds a new attribute, you need to apply ConfigurationPropertyAttribute to the new attribute, for example:
[ConfigurationProperty("providerName",IsRequired=true)] publicvirtualstringProviderName { get { returnthis["ProviderName"]asstring; } set { this["ProviderName"]=value; } }
The configuration method in the configuration file is as follows:
Note that in the section below is the behavior we extended and providerName is the property added to MyBehaviorExtensionElement. If IEndpointBehavior is extended, the name of the configuration section is. Section is responsible for adding extensions to custom behavior. where the value of name in corresponds to the value below.
The above is "WCF interface how to use" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.