ComContractElement.UserDefinedTypes 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會獲得一組用戶定義類型(UDT)的集合,這些資料將納入服務合約中。 此類別無法獲得繼承。
public:
property System::ServiceModel::Configuration::ComUdtElementCollection ^ UserDefinedTypes { System::ServiceModel::Configuration::ComUdtElementCollection ^ get(); };
[System.Configuration.ConfigurationProperty("userDefinedTypes")]
public System.ServiceModel.Configuration.ComUdtElementCollection UserDefinedTypes { get; }
[<System.Configuration.ConfigurationProperty("userDefinedTypes")>]
member this.UserDefinedTypes : System.ServiceModel.Configuration.ComUdtElementCollection
Public ReadOnly Property UserDefinedTypes As ComUdtElementCollection
屬性值
使用者定義型別(UDT)集合。
- 屬性
範例
以下範例示範在此目的中新增兩個特定的 UDT <userDefinedTypes> 到設定檔區段。
<comContracts>
<comContract contract="{5163B1E7-F0CF-4B6A-9A02-4AB654F34284}"
namespace="http://tempuri.org/5163B1E7-F0CF-4B6A-9A02-4AB654F34284"
name="_Broker" requiresSession="true">
<userDefinedTypes>
<userDefinedType name="CustomerType"
typeLibID="{91DC728C-4F1A-45de-A9B6-B538E209CEA6}"
typeLibVersion="1.0"
typeDefID="{D129765C-F211-434e-825A-9A63198C41F2}" />
<userDefinedType name="AddressType"
typeLibID="{91DC728C-4F1A-45de-A9B6-B538E209CEA6}"
typeLibVersion="1.0"
typeDefID="{4616AE0D-687A-43B7-BC63-141AE3DFD099}" />
</userDefinedTypes>
<exposedMethods>
<add exposedMethod ="BuyStock" />
<add exposedMethod ="SellStock" />
<add exposedMethod ="ExecuteTransaction" />
</exposedMethods>
</comContract>
</comContracts>
元素 <userDefinedType> 的屬性定義如下:
typeName: 一個可選屬性,提供可讀型別名稱。 執行時不會使用這點,但有助於讀者區分類型。typeLibID: 一個 GUID 字串,用來指定定義該型別的註冊型別庫。typeLibVersion: 一個字串,用來指定定義型別的型別庫版本。typeDefID: 一個 GUID 字串,用來指定註冊型態函式庫中特定 UDT 類型。
服務初始化時,整合執行時會查詢指定的類型,並將其加入指定合約的已知類型集合中。
備註
COM+ 整合執行時透過檢查型別函式庫來建立服務。 當 COM+ 元件包含傳遞 VARIANT 的方法時,系統無法在執行前判斷實際要傳遞的型別。 因此,當你嘗試在變體中傳遞使用者定義型別(UDT)時,該型別會失敗,因為它不是已知的序列化型別。
為了避免這個問題,你可以將 UDT 加入設定檔,讓它們能作為已知類型納入相應的服務合約中。 為此,你必須唯一地識別 UDT 及其合約,也就是使用該協定的原始 COM 介面。