日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

元数据交换绑定的秘密

發布時間:2025/7/14 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 元数据交换绑定的秘密 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

WCF提供了一種特殊的終結點——元數據交換終結點(MEX終結點),通過它,服務就能夠發布元數據。此外,它專門提供了一個元數據交換的服務契約接口IMetadataExchange:

[ServiceContract]
public?interface?IMetadataExchange
{
??? [OperationContract]
??? Message Get(Message request);
}

既然要配置終結點,就必須有對應的綁定來支持。MEX終結點可以支持多種不同的傳輸協議,包括HTTP(S),TCP和Named Pipe,支持MEX傳輸的綁定的名稱分別為mexHttpBinding、mexHttpsBinding、mexTcpBinding、 mexNamedPipeBinding。例如,這樣的配置文件:

<endpoint
??? address =?"MEX"
??? binding =?"mexHttpBinding"
??? contract =?"IMetadataExchange"
/>
<endpoint
??? address =?"MEX"
??? binding =?"mexTcpBinding"
??? contract =?"IMetadataExchange"
/>

那么,是否需要為MEX終結點配置一個相應的綁定呢?不過,如果我們試著去查找System.ServiceModel等與WCF有關的程序集,是找不到這樣的綁定類的。Aaron Skonnard在其博客中揭開了一個秘密,他認為,在這里,微軟的開發人員玩了一個花招,那些綁定元素并沒有分別映射到一個專門的類中,而是統一放到了一個單獨的類MetadataExchangeBindings,(The trick is these binding element names don't map to individual classes but rather to a single class named MetadataExchangeBindings.)它提供了CreateMexHttpBinding, CreateMexHttpsBinding, CreateMexNamedPipeBinding和CreateMexTcpBinding四個方法,如下所示:

public?static?class?MetadataExchangeBindings
{
????// Methods
????public?static?Binding CreateMexHttpBinding();
????public?static?Binding CreateMexHttpsBinding();
????public?static?Binding CreateMexNamedPipeBinding();
????public?static?Binding CreateMexTcpBinding();
????//...
}

查看這些方法的實現,可以發現它們都創建了WCF的內建綁定,然后根據情況調整了某些默認值,并重寫了綁定的名稱和命名空間(If you inspect the implementation of any of these methods, you'll notice they just create one of the built-in bindings, adjusting some of the defaults, and then they override the binding name and namespace.),例如:

public?static?Binding CreateMexHttpBinding()
{
????return?CreateHttpBinding();
}

private?static?WSHttpBinding CreateHttpBinding()
{
??? WSHttpBinding binding =?new?WSHttpBinding(SecurityMode.None,?false);
??? binding.Name =?"MetadataExchangeHttpBinding";
??? binding.Namespace =?"http://schemas.microsoft.com/ws/2005/02/mex/bindings";
????return?binding;
}

這樣做的目的是由于不同傳輸協議的MEX終結點在配置文件中的配置只是稍有不同,為了元數據交換而專門定義一個新的綁定,是沒有意義的。(they probably figured it wouldn't make sense to define completely new binding classes just for the MEX scenarios...they're really just slightly different configurations.

從這一實現可以看出,當我們在配置MEX終結點時,使用WCF提供的MEX綁定并非必須的,我們也可以為其指定內建綁定,只要該綁定符合MEX終結點的場景。







本文轉自wayfarer51CTO博客,原文鏈接:http://blog.51cto.com/wayfarer/280126,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的元数据交换绑定的秘密的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。