首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

WCF 服務發布 WSDL 基礎篇:ServiceMetadataBehavior 與 MEX 端點詳解

     編輯:關於.NET

ServiceMetadataBehavior 是實現元資料發布的核心服務行為,支援 HTTP-GET 與 WS-MEX 兩種協定。本文介紹其屬性、組態對應 ServiceMetadataPublishingElement,以及 MEX 端點的特殊契約 IMetadataExchange 與專用繫結 MetadataExchangeBindings。

ServiceMetadataBehavior 主要屬性

  • ExternalMetadataLocation:外部元資料位址。
  • HttpGetEnabled/HttpGetUrl/HttpGetBinding:HTTP-GET 發布設定。
  • HttpsGetEnabled/HttpsGetUrl/HttpsGetBinding:HTTPS-GET 發布設定。
  • MetadataExporter:元資料導出器(預設 WsdlExporter)。

對應組態元素 <serviceMetadata> 可設定上述屬性外,另提供 policyVersion 指定 WS-Policy 版本。

<behavior name="MetadataPublishBehavior">
  <serviceMetadata externalMetadataLocation="https://127.0.1/mex/calculatorservice"
      httpGetEnabled="true" httpGetUrl="https://127.0.0.1/calculatorservice/mex"
      httpsGetEnabled="true" httpsGetUrl="https://127.0.0.1/calculatorservice/mex"
      policyVersion="Policy15" />
</behavior>

MEX 端點的特殊性

1. 契約:IMetadataExchange

定義於 System.ServiceModel.Description,僅含 Get(Message) 操作(同步與非同步),Action/ReplyAction 依 WS-Transfer Get 規範。ConfigurationName 設為 "IMetadataExchange",故組態可直接寫 contract="IMetadataExchange"。

2. 繫結:MetadataExchangeBindings

靜態類別提供四種建立方法:CreateMexHttpBinding、CreateMexHttpsBinding、CreateMexTcpBinding、CreateMexNamedPipeBinding。組態對應 mexHttpBinding、mexHttpsBinding、mexTcpBinding、mexNamedPipeBinding。

<endpoint address="https://127.0.0.1/calculatorservice/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="https://127.0.0.1/calculatorservice/mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<endpoint address="net.tcp://127.0.0.1/calculatorservice/mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="net.pipe://127.0.0.1/calculatorservice/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />

下一篇將深入剖析 ServiceMetadataBehavior 內部如何實現兩種協定的發布邏輯。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved