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 to configure child nodes in WCF

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how WCF configures its child nodes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

WCF configuration child node Services: there is already a service named CatalogService in the file, which implements the same class name for the service. Under the Service node, you can see Endpoint, which contains the ABCs:Address (address), binding (binding) and contract (contract) of the service.

◆ Address: you will find that the address is empty, so don't worry, because the svc file will serve as the base

◆ Binding: webHttpBinding is a new binding provided by WCF3.5 that allows services to be published as REST. There are two modes for this binding, and you can specify the mode through a specific endpoint behavior (by setting behaviorConfiguration)

◆ Contract: contract specifies the functionality provided by the WCF service. This property is set to a service agreement that has been defined. To define a service contract, you can decorate an interface or class with ServiceContract. In an interface or class modified by ServiceContract, all methods modified by OperationContract will be exposed to the customer as an operation of the service. Generally speaking, it is better to use an interface as a service agreement, which has the advantage of separating the agreement from the specific implementation. But the method of the class is used in the template we use, that is, the interface is automatically inferred from the class (interface inference).

◆ BehaviorConfiguration: for webHttpBinding, you need to set this property to an endpoint behavior that has a webHttp or enableWebscript child node.

Comprehensive description of the reliable transmission performance of WCF

A case study of orderly transfer of WCF by programming

Disclosure of WCF Service metadata Exchange programming

One-to-one connection of three WCF service modes

Talking about WCF transaction attributes

F configure child node Behaviors: the purpose of adding behaviors to a service or service endpoint is to change the default behavior of runtime or to add custom extensions. You will find that the template we use already declares an endpoint behavior named CatalogServiceAspNetAjaxBehavior. This behavior has an enableWebScript element. EnableWebScript is one of two possible endpoint behaviors, and the other is webHttp. In fact, enableWebScript is a subclass that webHttp uses to provide AJAX functions, such as generating client proxies

WCF configuration child node ServiceHostingEnvironment: the default configuration of the WCF service running with ASP.Net is that the two do not interfere with each other, for example, ASP.NET runtime does not participate in the processing of WCF requests. WCF services also cannot use features such as ASP.NET context and session. Our configuration here is to set aspNetCompatibilityEnabled to true, in which case the WCF request will be added to the ASP.Net request pipeline.

* for WCF to support REST, just note the two most important points in the configuration file: 1) binding should be set to webHttpBinding 2) endpoint behavior should be set to webHttp or enableWebScript

CatalogService.cs [ServiceContract (Namespace = ")] [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class CatalogService {/ / Add [WebGet] attribute to use HTTP GET [OperationContract] public void DoWork () {/ / Add your operation implementation here return;} / / Add more operations here and mark them with [OperationContract]}

We really have to do something here. If you have read the above, you should have noticed that we have defined the service contract with the method inferred by the interface, that is, decorating a class instead of an interface with the ServiceContract attribute. Anyway, we're going to start to make it happen a little bit. The * thing is to set the NameSpace parameter of the ServiceContract property. This is very important. This is where the namespace of the proxy used by the client to invoke the WCF service is taken.

Thank you for reading! This is the end of the article on "how to configure child nodes in WCF". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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