Share via


ComContractElement.UserDefinedTypes 屬性

定義

取得要包含在服務合約中之使用者定義型別 (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 的方法時,系統便無法在執行階段之前判斷要傳遞的實際型別。 因此,嘗試在 VARIANT 內傳遞使用者定義型別 (UDT) 會因為該型別不是序列化的已知型別而失敗。

如果要避免這個問題,您可以將這些 UDT 新增至組態檔中,以便包含它們做為適當服務合約中的已知型別。 如果要這樣做,您必須唯一識別這些 UDT 和合約,也就是使用其原始的 COM 介面。

適用於