惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
IT之家
IT之家
T
The Blog of Author Tim Ferriss
V
V2EX
博客园 - 聂微东
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
U
Unit 42
Vercel News
Vercel News
L
LangChain Blog
博客园 - 司徒正美
H
Help Net Security
Recent Announcements
Recent Announcements
Recorded Future
Recorded Future
V
Visual Studio Blog
Jina AI
Jina AI
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
Y
Y Combinator Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
F
Fortinet All Blogs
B
Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园_首页
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
量子位
I
InfoQ
小众软件
小众软件
P
Proofpoint News Feed

博客园 - JerryShi

使用流模式传输大型数据 对象序列化之 替换(Surrogate) 使用 IExtensibleDataObject 进行往返式序列化 使用 NetDataContractSerializer 共享类型 WCF可序列化方式 序列化 VS 编码 自定义 Behavior 操作行为 之 事务 服务行为 之 并发与实例化 基本的WCF编程(实例) WCF Behaviors(行为) WCF 体系结构 WCF服务 使用netTcpBinding 无法打开默认数据库 SharePoint 创建SSP时出现找不到 Windows NT 用户或组 的异常 SQL Server 2008 Mirror 泛型(一) 自定义属性Attribute(三) 自定义属性Attribute(二)
服务行为 之 元数据
JerryShi · 2011-09-28 · via 博客园 - JerryShi

元数据:将服务的ABC(地址、绑定、契约)以 服务提供者与服务消费者共同认可的XML 描述的形式描述出来。

要使元数据对客户端可用,需要两个步骤:

1. 按某种可读的格式导出元数据;

2. 发布到一个可用的位置;

默认的导出格式是WSDL,WCF使用WS-MetadataExchange协议发布元数据,或者将元数据发布为HTTP GET的

Response。导出与发布的操作都由 ServiceMetadataBehavior 实现

服务通过Mex端点交换数据,Mex端点类似于我们开发的端点,同样有自己的 ABC,同样可以通过配置文件进行添加。

Mex端点的ABC及示例

契约: System.ServiceModel.Description.IMetadataExchange 接口,其服务实现了检查服务并以WSDL格式提供和发布元数据的方法;

绑定: CLR提供的绑定:mexHttpBinding、mexHttpsBinding、mexNamedPipeBinding、mexTcpBinding;

地址: 地址可以是相对地址,也可以是绝对地址,通常配置文件中相对地址为mex

Mex端点自托管代码

using (ServiceHost servcieHost = new ServiceHost(typeof(StockService), new Uri(url)))
            {
                servcieHost.AddServiceEndpoint(typeof(IStockService), binding, "");

                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                servcieHost.Description.Behaviors.Add(behavior);
                servcieHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

                servcieHost.Open();

                Console.WriteLine("Press  to terminate service...");
                Console.ReadLine();
                servcieHost.Close();
            }