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

What is the WCF service metadata structure pattern?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "what is the WCF service metadata structure pattern". In the daily operation, I believe many people have doubts about what the WCF service metadata structure model is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what the WCF service metadata structure pattern is like." Next, please follow the editor to study!

After a long period of development of WCF, many users have a good understanding of WCF service metadata. Here I would like to publish my personal understanding and discuss it with you. The so-called access to WCF service metadata (Metadata), in the final analysis, is actually obtaining the information of the Endpoint of the service, which is the data information exposed by the service, including Address, Binding and Contract, that is, the so-called ABCs. In his book Programming WCF Services, Juval L?wy uses vivid lollipops to represent the composition of endpoints:

WCF service metadata may contain multiple endpoints, each of which acts as an entry point for communication. Clients and servers exchange information through endpoints, as shown in the following figure:

Therefore, if we can get the details of the endpoint, it will help us to better analyze the definition, content and execution of the service. There are two scenarios for services to publish their own metadata. One is to provide metadata based on HTTP-GET protocol; the other is metadata exchange, which often uses a special endpoint, which is called metadata exchange endpoint. Metadata exchange endpoints, like other endpoints, still contain addresses, bindings, and contracts, but the service contract used is the interface IMetadataExchange provided by WCF. In fact, these two ways of publishing metadata represent that it uses two different standard protocols, the former for HTTP/GET requests and the latter for WS-MetadataExchange (MEX). In WCF, the two metadata exchange modes are represented by the MetadataExchangeClientMode enumeration type:

Public enum MetadataExchangeClientMode {MetadataExchange, HttpGet}

WCF defines a special ServiceEndpoint class for endpoints, which is defined in the System.ServiceModel.Description namespace. The ServiceEndpoint class contains three types of attributes of EndpointAddress,Binding,ContractDescription, corresponding to the Address,Binding,Contract of Endpoint, as shown below:

To get the endpoint of the service, you can obtain it through the abstract class MetadataImporter, which is defined as follows:

Public abstract class MetadataImporter {public abstract Collection ImportAllContracts (); public abstract ServiceEndpointCollection ImportAllEndpoints (); / / other methods;}

The most important method in the class is ImportAllEndpoints (), which gets all the endpoints of the service and returns an object of type ServiceEndpointCollection. This type is a collection of endpoints, and one or more endpoints that match the criteria can be found by calling the Find () method or the FindAll () method of ServiceEndpointCollection. It is defined as follows:

Public class ServiceEndpointCollection: Collection {public ServiceEndpoint Find (Type contractType); public ServiceEndpoint Find (Uri address); public Collection FindAll (Type contractType); / / other members slightly}

We can find eligible endpoints by the contract type, or the address of the service contract.

At this point, the study on "what the WCF service metadata structure pattern is like" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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