当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

[WCF]契约查询ContractQueries

责任编辑:nancy作者:ITPUB论坛   2008-05-20   
文本Tag: 微软 sql

【IT168技术文档】

  当我们拿到一个服务地址的时候该如何知道这个服务所提供的服务呢?如果是您自己开发的Service,这一点或许不需要兴师动众,但是如果是别人开发的服务,那么了解服务中的Endpoint将显得格外重要,本文将利用对[WCF]继承中所构建的服务代码进行分析。

  打开其程序代码添加一个ConsoleApplication应用程序,新建程序,代码如下:
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<ContractDescription> 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++; } } } }
  这个项目我们不需要Add ServiceReference,因为我们只需分析那个“地址”所提供给我们的究竟是什么样的服务,而不是要去使用服务中的契约。
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-05-20/200805200814062.shtml
技术开发相关文章   .net server SQL 微软
  • 暂无
友情推介