ServiceDescriptionFormatExtensionCollection 类

定义

表示 XML Web 服务所使用的可扩展性元素的集合。 此类不能被继承。

public ref class ServiceDescriptionFormatExtensionCollection sealed : System::Web::Services::Description::ServiceDescriptionBaseCollection
public sealed class ServiceDescriptionFormatExtensionCollection : System.Web.Services.Description.ServiceDescriptionBaseCollection
type ServiceDescriptionFormatExtensionCollection = class
    inherit ServiceDescriptionBaseCollection
Public NotInheritable Class ServiceDescriptionFormatExtensionCollection
Inherits ServiceDescriptionBaseCollection
继承
ServiceDescriptionFormatExtensionCollection

示例

#using <System.Web.Services.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Web::Services::Description;
using namespace System::Collections;

ref class MyFormatExtension: public ServiceDescriptionFormatExtension
{
public:
   MyFormatExtension()
   {
      // Set the properties.
      this->Handled = true;
      this->Required = true;
   }
};

int main()
{
   try
   {
      ServiceDescription^ myServiceDescription = ServiceDescription::Read( "Sample_cpp.wsdl" );
      ServiceDescriptionFormatExtensionCollection^ myCollection = gcnew ServiceDescriptionFormatExtensionCollection( myServiceDescription );

      SoapBinding^ mySoapBinding1 = gcnew SoapBinding;
      SoapBinding^ mySoapBinding2 = gcnew SoapBinding;
      SoapAddressBinding^ mySoapAddressBinding = gcnew SoapAddressBinding;
      MyFormatExtension^ myFormatExtensionObject = gcnew MyFormatExtension;

      // Add elements to collection.
      myCollection->Add( mySoapBinding1 );
      myCollection->Add( mySoapAddressBinding );
      myCollection->Add( mySoapBinding2 );
      myCollection->Add( myFormatExtensionObject );

      Console::WriteLine( "Collection contains following types of elements: " );
      
      // Display the 'Type' of the elements in collection.
      for ( int i = 0; i < myCollection->Count; i++ )
         Console::WriteLine( myCollection[ i ]->GetType() );

      // Check element of type 'SoapAddressBinding' in collection.
      Object^ myObj = myCollection->Find( mySoapAddressBinding->GetType() );
      if ( myObj == nullptr )
            Console::WriteLine( "Element of type ' {0}' not found in collection.", mySoapAddressBinding->GetType() );
      else
            Console::WriteLine( "Element of type ' {0}' found in collection.", mySoapAddressBinding->GetType() );

      // Check all elements of type 'SoapBinding' in collection.
      array<Object^>^myObjectArray1 = gcnew array<Object^>(myCollection->Count);
      myObjectArray1 = myCollection->FindAll( mySoapBinding1->GetType() );
      int myNumberOfElements = 0;
      IEnumerator^ myIEnumerator = myObjectArray1->GetEnumerator();

      // Calculate number of elements of type 'SoapBinding'.
      while ( myIEnumerator->MoveNext() )
            if ( mySoapBinding1->GetType() == myIEnumerator->Current->GetType() )
            myNumberOfElements++;
      Console::WriteLine( "Collection contains {0} objects of type ' {1}'.", myNumberOfElements, mySoapBinding1->GetType() );

      // Check 'IsHandled' status for 'myFormatExtensionObject' object in collection.
      Console::WriteLine( "'IsHandled' status for {0} object is {1}.", myFormatExtensionObject, myCollection->IsHandled( myFormatExtensionObject ) );

      // Check 'IsRequired' status for 'myFormatExtensionObject' object in collection.
      Console::WriteLine( "'IsRequired' status for {0} object is {1}.", myFormatExtensionObject, myCollection->IsRequired( myFormatExtensionObject ) );

      // Copy elements of collection to an Object array.
      array<Object^>^myObjectArray2 = gcnew array<Object^>(myCollection->Count);
      myCollection->CopyTo( myObjectArray2, 0 );
      Console::WriteLine( "Collection elements are copied to an object array." );

      // Check for 'myFormatExtension' object in collection.
      if ( myCollection->Contains( myFormatExtensionObject ) )
      {
         // Get index of a 'myFormatExtension' object in collection.
         Console::WriteLine( "Index of 'myFormatExtensionObject' is {0} in collection.", myCollection->IndexOf( myFormatExtensionObject ) );

         // Remove 'myFormatExtensionObject' element from collection.
         myCollection->Remove( myFormatExtensionObject );
         Console::WriteLine( "'myFormatExtensionObject' is removed  from collection." );
      }

      // Insert 'MyFormatExtension' object.
      myCollection->Insert( 0, myFormatExtensionObject );
      Console::WriteLine( "'myFormatExtensionObject' is inserted to collection." );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The following exception was raised: {0}", e->Message );
   }
}
using System;
using System.Web.Services.Description;
using System.Collections;

class MyFormatExtension : ServiceDescriptionFormatExtension
{
   public MyFormatExtension()
   {
      // Set the properties.
      this.Handled  = true;
      this.Required = true;
   }
}
class myCollectionSample
{
   static void Main()
   {
      try
      {
         ServiceDescription myServiceDescription =
            ServiceDescription.Read("Sample_CS.wsdl");
         ServiceDescriptionFormatExtensionCollection  myCollection =
            new ServiceDescriptionFormatExtensionCollection(myServiceDescription);
         SoapBinding mySoapBinding1 = new SoapBinding();
         SoapBinding mySoapBinding2 = new SoapBinding();
         SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();
         MyFormatExtension  myFormatExtensionObject = new MyFormatExtension();
         // Add elements to collection.
         myCollection.Add(mySoapBinding1);
         myCollection.Add(mySoapAddressBinding);
         myCollection.Add(mySoapBinding2);
         myCollection.Add(myFormatExtensionObject);
         Console.WriteLine("Collection contains following types of elements: ");
         // Display the 'Type' of the elements in collection.
         for(int i = 0;i< myCollection.Count;i++)
         {
            Console.WriteLine(myCollection[i].GetType().ToString());
         }
         // Check element of type 'SoapAddressBinding' in collection.
         Object   myObj = myCollection.Find(mySoapAddressBinding.GetType());
         if(myObj == null)
         {
            Console.WriteLine("Element of type '{0}' not found in collection.",
               mySoapAddressBinding.GetType().ToString());
         }
         else
         {
            Console.WriteLine("Element of type '{0}' found in collection.",
               mySoapAddressBinding.GetType().ToString());
         }
         // Check all elements of type 'SoapBinding' in collection.
         Object[] myObjectArray1 = new Object[myCollection.Count];
         myObjectArray1 = myCollection.FindAll(mySoapBinding1.GetType());
         int myNumberOfElements = 0;
         IEnumerator myIEnumerator  = myObjectArray1.GetEnumerator();

         // Calculate number of elements of type 'SoapBinding'.
         while(myIEnumerator.MoveNext())
         {
            if(mySoapBinding1.GetType() == myIEnumerator.Current.GetType())
               myNumberOfElements++;
         }
         Console.WriteLine("Collection contains {0} objects of type '{1}'.",
                           myNumberOfElements.ToString(),
                           mySoapBinding1.GetType().ToString());
         // Check 'IsHandled' status for 'myFormatExtensionObject' object in collection.
         Console.WriteLine("'IsHandled' status for {0} object is {1}.",
                  myFormatExtensionObject.ToString(),
                  myCollection.IsHandled(myFormatExtensionObject).ToString());
         // Check 'IsRequired' status for 'myFormatExtensionObject' object in collection.
         Console.WriteLine("'IsRequired' status for {0} object is {1}.",
                  myFormatExtensionObject.ToString(),
                  myCollection.IsRequired(myFormatExtensionObject).ToString());
         // Copy elements of collection to an Object array.
         Object[] myObjectArray2 = new Object[myCollection.Count];
         myCollection.CopyTo(myObjectArray2,0);
         Console.WriteLine("Collection elements are copied to an object array.");
         // Check for 'myFormatExtension' object in collection.
         if(myCollection.Contains(myFormatExtensionObject))
         {
            // Get index of a 'myFormatExtension' object in collection.
            Console.WriteLine("Index of 'myFormatExtensionObject' is "+
               "{0} in collection.",
               myCollection.IndexOf(myFormatExtensionObject).ToString());
            // Remove 'myFormatExtensionObject' element from collection.
            myCollection.Remove(myFormatExtensionObject);
            Console.WriteLine("'myFormatExtensionObject' is removed"+
                              " from collection.");
         }
         // Insert 'MyFormatExtension' object.
         myCollection.Insert(0,myFormatExtensionObject);
         Console.WriteLine("'myFormatExtensionObject' is inserted to collection.");
      }
      catch(Exception e)
      {
         Console.WriteLine("The following exception was raised: {0}", e.Message);
      }
   }
}
Imports System.Web.Services.Description
Imports System.Collections


Class MyFormatExtension
   Inherits ServiceDescriptionFormatExtension
   
   Public Sub New()
      ' Set the properties.
      Me.Handled = True
      Me.Required = True
   End Sub
End Class

Class myCollectionSample
   
   Shared Sub Main()
      Try
         Dim myServiceDescription As ServiceDescription = _
                 ServiceDescription.Read("Sample_VB.wsdl")
         Dim myCollection As New ServiceDescriptionFormatExtensionCollection(myServiceDescription)
         Dim mySoapBinding1 As New SoapBinding()
         Dim mySoapBinding2 As New SoapBinding()
         Dim mySoapAddressBinding As New SoapAddressBinding()
         Dim myFormatExtensionObject As New MyFormatExtension()
         ' Add elements to collection.
         myCollection.Add(mySoapBinding1)
         myCollection.Add(mySoapAddressBinding)
         myCollection.Add(mySoapBinding2)
         myCollection.Add(myFormatExtensionObject)
         Console.WriteLine("Collection contains following types of elements: ")
         ' Display the 'Type' of the elements in collection.
         Dim i As Integer
         For i = 0 To myCollection.Count - 1
            Console.WriteLine(myCollection(i).GetType().ToString())
         Next i
         ' Check element of type 'SoapAddressBinding' in collection.
         Dim myObj As Object = myCollection.Find(mySoapAddressBinding.GetType())
         If myObj Is Nothing Then
            Console.WriteLine("Element of type '{0}' not found in collection.", _
                 mySoapAddressBinding.GetType().ToString())
         Else
            Console.WriteLine("Element of type '{0}' found in collection.", _
                 mySoapAddressBinding.GetType().ToString())
         End If
         ' Check all elements of type 'SoapBinding' in collection.
         Dim myObjectArray1(myCollection.Count -1 ) As Object
         myObjectArray1 = myCollection.FindAll(mySoapBinding1.GetType())
         Dim myNumberOfElements As Integer = 0
         Dim myIEnumerator As IEnumerator = myObjectArray1.GetEnumerator()
         
         ' Calculate number of elements of type 'SoapBinding'.
         While myIEnumerator.MoveNext()
            If mySoapBinding1.GetType() Is  myIEnumerator.Current.GetType() Then
               myNumberOfElements += 1
            End If
         End While
         Console.WriteLine("Collection contains {0} objects of type '{1}'.", _
                 myNumberOfElements.ToString(), mySoapBinding1.GetType().ToString())
         ' Check 'IsHandled' status for 'myFormatExtensionObject' object in collection.
         Console.WriteLine("'IsHandled' status for {0} object is {1}.", _
                 myFormatExtensionObject.ToString(), _
                 myCollection.IsHandled(myFormatExtensionObject).ToString())
         ' Check 'IsRequired' status for 'myFormatExtensionObject' object in collection.
         Console.WriteLine("'IsRequired' status for {0} object is {1}.", _
                 myFormatExtensionObject.ToString(), _
                 myCollection.IsRequired(myFormatExtensionObject).ToString())
         ' Copy elements of collection to an Object array.
         Dim myObjectArray2(myCollection.Count -1 ) As Object
         myCollection.CopyTo(myObjectArray2, 0)
         Console.WriteLine("Collection elements are copied to an object array.")
         ' Check for 'myFormatExtension' object in collection.
         If myCollection.Contains(myFormatExtensionObject) Then
            ' Get index of a 'myFormatExtension' object in collection.
            Console.WriteLine("Index of 'myFormatExtensionObject' is " + _
                 "{0} in collection.", myCollection.IndexOf(myFormatExtensionObject).ToString())
            ' Remove 'myFormatExtensionObject' element from collection.
            myCollection.Remove(myFormatExtensionObject)
            Console.WriteLine("'myFormatExtensionObject' is removed" + _
                 " from collection.")
         End If
         ' Insert 'MyFormatExtension' object.
         myCollection.Insert(0, myFormatExtensionObject)
         Console.WriteLine("'myFormatExtensionObject' is inserted to collection.")
      Catch e As Exception
         Console.WriteLine("The following exception was raised: {0}", e.Message.ToString())
      End Try
   End Sub
End Class

注解

此集合可以包含派生自 ServiceDescriptionFormatExtension的类的实例或类的 XmlElement 实例。 在派生类中, ServiceDescriptionFormatExtension 类允许用户定义扩展性元素,除了在 Web 服务说明语言 (WSDL) 规范中定义的元素之外。 如果事先知道要创建的扩展性元素的类型,请使用这些 ServiceDescriptionFormatExtensionCollection 元素。 XmlElement提前不知道元素的格式时使用。

构造函数

ServiceDescriptionFormatExtensionCollection(Object)

初始化 ServiceDescriptionFormatExtensionCollection 类的新实例。

属性

Capacity

获取或设置 CollectionBase 可包含的元素数。

(继承自 CollectionBase)
Count

获取 CollectionBase 实例中包含的元素数。 不能重写此属性。

(继承自 CollectionBase)
InnerList

获取一个 ArrayList,它包含 CollectionBase 实例中元素的列表。

(继承自 CollectionBase)
Item[Int32]

获取或设置 ServiceDescriptionFormatExtensionCollection 的成员的值。

List

获取一个 IList,它包含 CollectionBase 实例中元素的列表。

(继承自 CollectionBase)
Table

获取实现 ServiceDescriptionBaseCollection 中键和值的关联的接口。

(继承自 ServiceDescriptionBaseCollection)

方法

Add(Object)

将指定的 ServiceDescriptionFormatExtension 添加到 ServiceDescriptionFormatExtensionCollection 的结尾。

Clear()

CollectionBase 实例移除所有对象。 不能重写此方法。

(继承自 CollectionBase)
Contains(Object)

返回一个值,该值指示指定的 ServiceDescriptionFormatExtension 是否是 ServiceDescriptionFormatExtensionCollection 的成员。

CopyTo(Object[], Int32)

将整个 ServiceDescriptionFormatExtensionCollection 复制到 ServiceDescriptionFormatExtension 类型的一维数组中(从目标数组的指定的从零开始的索引处开始)。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Find(String, String)

搜索 ServiceDescriptionFormatExtensionCollection 以查找具有指定名称和命名空间 URI 的成员。

Find(Type)

搜索 ServiceDescriptionFormatExtensionCollection,并返回指定的派生 Type 的第一个元素。

FindAll(String, String)

搜索 ServiceDescriptionFormatExtensionCollection 并返回具有指定名称和命名空间 URI 的所有成员的数组。

FindAll(Type)

搜索 ServiceDescriptionFormatExtensionCollection 并返回指定的 Type 的所有元素的数组。

GetEnumerator()

返回循环访问 CollectionBase 实例的枚举器。

(继承自 CollectionBase)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetKey(Object)

返回与通过引用传递的值关联的键的名称。

(继承自 ServiceDescriptionBaseCollection)
GetType()

获取当前实例的 Type

(继承自 Object)
IndexOf(Object)

搜索指定的 ServiceDescriptionFormatExtension,并返回集合中第一个实例的从零开始的索引。

Insert(Int32, Object)

将指定的 ServiceDescriptionFormatExtension 添加到 ServiceDescriptionFormatExtensionCollection 中指定的从零开始的索引处。

IsHandled(Object)

返回一个值,该值指示当扩展性元素导入 XML Web services 时,导入进程是否使用指定的对象。

IsRequired(Object)

返回一个值,该值指示指定的对象是否对于 XML Web services 的操作是必需的。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnClear()

清除 ServiceDescriptionBaseCollection 实例的内容。

(继承自 ServiceDescriptionBaseCollection)
OnClearComplete()

在清除 CollectionBase 实例的内容之后执行其他自定义进程。

(继承自 CollectionBase)
OnInsert(Int32, Object)

在向 CollectionBase 实例中插入新元素之前执行其他自定义进程。

(继承自 CollectionBase)
OnInsertComplete(Int32, Object)

将新元素插入 ServiceDescriptionBaseCollection 后,执行附加的自定义进程。

(继承自 ServiceDescriptionBaseCollection)
OnRemove(Int32, Object)

ServiceDescriptionBaseCollection 中移除一个元素。

(继承自 ServiceDescriptionBaseCollection)
OnRemoveComplete(Int32, Object)

在从 CollectionBase 实例中移除元素之后执行其他自定义进程。

(继承自 CollectionBase)
OnSet(Int32, Object, Object)

ServiceDescriptionBaseCollection 中的一个值替换另一个值。

(继承自 ServiceDescriptionBaseCollection)
OnSetComplete(Int32, Object, Object)

当在 CollectionBase 实例中设置值后执行其他自定义进程。

(继承自 CollectionBase)
OnValidate(Object)

当验证值时执行其他自定义进程。

(继承自 CollectionBase)
Remove(Object)

ServiceDescriptionFormatExtension 中移除指定的 ServiceDescriptionFormatExtensionCollection 的第一个匹配项。

RemoveAt(Int32)

移除 CollectionBase 实例的指定索引处的元素。 此方法不可重写。

(继承自 CollectionBase)
SetParent(Object, Object)

设置 ServiceDescriptionBaseCollection 实例的父对象。

(继承自 ServiceDescriptionBaseCollection)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 CollectionBase 复制到兼容的一维 Array

(继承自 CollectionBase)
ICollection.IsSynchronized

获取一个值,该值指示是否同步对 CollectionBase 的访问(线程安全)。

(继承自 CollectionBase)
ICollection.SyncRoot

获取可用于同步对 CollectionBase 的访问的对象。

(继承自 CollectionBase)
IList.Add(Object)

将对象添加到 CollectionBase 的结尾处。

(继承自 CollectionBase)
IList.Contains(Object)

确定 CollectionBase 是否包含特定元素。

(继承自 CollectionBase)
IList.IndexOf(Object)

搜索指定的 Object,并返回整个 CollectionBase 中第一个匹配项的从零开始的索引。

(继承自 CollectionBase)
IList.Insert(Int32, Object)

将元素插入 CollectionBase 的指定索引处。

(继承自 CollectionBase)
IList.IsFixedSize

获取一个值,该值指示 CollectionBase 是否具有固定大小。

(继承自 CollectionBase)
IList.IsReadOnly

获取一个值,该值指示 CollectionBase 是否为只读。

(继承自 CollectionBase)
IList.Item[Int32]

获取或设置指定索引处的元素。

(继承自 CollectionBase)
IList.Remove(Object)

CollectionBase 中移除特定对象的第一个匹配项。

(继承自 CollectionBase)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于