In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "WCF contract query ConsoleApplication application case analysis". In daily operation, I believe many people have doubts about WCF contract query ConsoleApplication application case analysis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "WCF contract query ConsoleApplication application case analysis". Next, please follow the editor to study!
How do we know the service provided by the service when we get a service address? If you developed the Service yourself, this may not require a lot of effort, but if it is a service developed by someone else, it is particularly important to understand the Endpoint in the service, and this article will analyze the service code built in [WCF] inheritance.
Programmers familiar with Web Service development should be familiar with adding service references. When creating a client program for a service, you do not need to write the underlying communication and interaction code of the client from scratch. You can add the service by entering the service address to let Visual Studio generate a client proxy, so that accessing the service is like accessing the local component without paying attention to the details of the communication. If the client program project and the service program project are in the same solution (many developers develop the client program synchronously when developing the service), you can also use Visual Studio to help us "Discovery" the service and add service references.
Open its program code and add a WCF contract query ConsoleApplication application, and create a new program. The WCF contract query code is as follows:
Using System
Using System.ServiceModel.Description
Namespace ContractQueriesClient
{
Class Program
{
Static void Main (string [] args)
{
/ /? WSDL
/ / string mexAddress = "http://localhost:8080/ScientificCalculatorService?WSDL";
/ / MetadataExchangeClient MEXClient = new MetadataExchangeClient (new Uri (mexAddress), MetadataExchangeClientMode.HttpGet)
/ MEX string mexAddress = "http://localhost:8080/ScientificCalculatorService/mex";
MetadataExchangeClient MEXClient = new MetadataExchangeClient (new Uri (mexAddress), MetadataExchangeClientMode.MetadataExchange)
MetadataSet metadata = MEXClient.GetMetadata ()
MetadataImporter importer = new WsdlImporter (metadata)
ServiceEndpointCollection endpoints = importer.ImportAllEndpoints ()
Int endpointCounter = 0
Foreach (ServiceEndpoint endpoint in endpoints)
{Console.WriteLine ("endpoints [{0}] .Name = {1}", endpointCounter, endpoint.Name)
Console.WriteLine ("endpoints [{0}] .Contract.Namespace = {1}", endpointCounter, endpoint.Contract.Namespace)
Console.WriteLine ("endpoints [{0}]. Contract.Name = {1}", endpointCounter, endpoint.Contract.Name); endpointCounter++;}
System.Collections.ObjectModel.Collection contracts = importer.ImportAllContracts ()
Int contractCounter = 0; foreach (ContractDescription contract in contracts)
{Console.WriteLine ("contracts [{0}] .Namespace = {1}", contractCounter, contract.Namespace)
Console.WriteLine ("contracts [{0}]. Name = {1}", contractCounter, contract.Name); contractCounter++;}
We don't need Add ServiceReference for this project, because we only need to analyze what kind of service that "address" provides to us, instead of using the WCF contract query in the service.
At this point, the study on "WCF contract query ConsoleApplication application example analysis" 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.