DiscoveryExceptionDictionary 类

定义

收集在发现 XML Web 服务期间发生的异常。 此类不能被继承。

public ref class DiscoveryExceptionDictionary sealed : System::Collections::DictionaryBase
public sealed class DiscoveryExceptionDictionary : System.Collections.DictionaryBase
type DiscoveryExceptionDictionary = class
    inherit DictionaryBase
Public NotInheritable Class DiscoveryExceptionDictionary
Inherits DictionaryBase
继承
DiscoveryExceptionDictionary

示例

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

using namespace System;
using namespace System::Web::Services::Discovery;
using namespace System::Xml;
using namespace System::Collections;
using namespace System::Runtime::Remoting;
using namespace System::Net;

int main()
{
   String^ myDiscoFile = "http://localhost/MathService_cs.disco";
   String^ myUrlKey = "http://localhost/MathService_cs.asmx?wsdl";
   DiscoveryClientProtocol^ myDiscoveryClientProtocol1 = gcnew DiscoveryClientProtocol;
   DiscoveryDocument^ myDiscoveryDocument = myDiscoveryClientProtocol1->Discover( myDiscoFile );
   IEnumerator^ myEnumerator = myDiscoveryDocument->References->GetEnumerator();
   while ( myEnumerator->MoveNext() )
   {
      ContractReference^ myContractReference = dynamic_cast<ContractReference^>(myEnumerator->Current);
      DiscoveryClientProtocol^ myDiscoveryClientProtocol2 = myContractReference->ClientProtocol;
      myDiscoveryClientProtocol2->ResolveAll();
      
      DiscoveryExceptionDictionary^ myExceptionDictionary = myDiscoveryClientProtocol2->Errors;
      if ( myExceptionDictionary->Contains( myUrlKey ) == true )
      {
         Console::WriteLine( "'myExceptionDictionary' contains a discovery exception for the key '{0}'", myUrlKey );
      }
      else
      {
         Console::WriteLine( "'myExceptionDictionary' does not contain a discovery exception for the key '{0}'", myUrlKey );
      }
      if ( myExceptionDictionary->Contains( myUrlKey ) == true )
      {
         Console::WriteLine( "System generated exceptions." );
         
         Exception^ myException = myExceptionDictionary[ myUrlKey ];
         Console::WriteLine( " Source : {0}", myException->Source );
         Console::WriteLine( " Exception : {0}", myException->Message );

         Console::WriteLine();
         
         // Remove the discovery exception.for the key 'myUrlKey'.
         myExceptionDictionary->Remove( myUrlKey );

         DiscoveryExceptionDictionary^ myNewExceptionDictionary = gcnew DiscoveryExceptionDictionary;
         
         // Add an exception with the custom error message.
         Exception^ myNewException = gcnew Exception( "The requested service is not available." );
         myNewExceptionDictionary->Add( myUrlKey, myNewException );
         myExceptionDictionary = myNewExceptionDictionary;

         Console::WriteLine( "Added exceptions." );
         
         array<Object^>^myArray = gcnew array<Object^>(myExceptionDictionary->Count);
         myExceptionDictionary->Keys->CopyTo( (Array^)myArray, 0 );
         Console::WriteLine( " Keys are :" );

         for each(Object^ myObj in myArray)
         {
            Console::WriteLine(" " + myObj->ToString());
         }

         Console::WriteLine();
         
         array<Object^>^myCollectionArray = gcnew array<Object^>(myExceptionDictionary->Count);
         myExceptionDictionary->Values->CopyTo( (Array^)myCollectionArray, 0 );
         Console::WriteLine( " Values are :" );
         for each(Object^ myObj in myCollectionArray)
         {
            Console::WriteLine(" " + myObj->ToString());
         }
      }
   }
}
using System;
using System.Web.Services.Discovery;
using System.Xml;
using System.Collections;
using System.Runtime.Remoting;
using System.Net;

public class MySample
{
   static void Main()
   {
      string myDiscoFile = "http://localhost/MathService_cs.disco";
      string myUrlKey = "http://localhost/MathService_cs.asmx?wsdl";
      DiscoveryClientProtocol myDiscoveryClientProtocol1 =
                                            new DiscoveryClientProtocol();
      DiscoveryDocument myDiscoveryDocument =
                         myDiscoveryClientProtocol1.Discover(myDiscoFile);
      IEnumerator myEnumerator =
                           myDiscoveryDocument.References.GetEnumerator();
      while ( myEnumerator.MoveNext() )
      {
         ContractReference myContractReference =
                                  (ContractReference)myEnumerator.Current;
         DiscoveryClientProtocol myDiscoveryClientProtocol2 =
                                       myContractReference.ClientProtocol;
         myDiscoveryClientProtocol2.ResolveAll();
         DiscoveryExceptionDictionary myExceptionDictionary
                                      = myDiscoveryClientProtocol2.Errors;
         if ( myExceptionDictionary.Contains(myUrlKey) == true )
         {
            Console.WriteLine("'myExceptionDictionary' contains " +
                      " a discovery exception for the key '" + myUrlKey + "'");
         }
         else
         {
            Console.WriteLine("'myExceptionDictionary' does not contain" +
                      " a discovery exception for the key '" + myUrlKey + "'");
         }
         if (myExceptionDictionary.Contains(myUrlKey) == true )
         {
            Console.WriteLine("System generated exceptions.");

            Exception myException = myExceptionDictionary[myUrlKey];
            Console.WriteLine(" Source : " + myException.Source);
            Console.WriteLine(" Exception : " + myException.Message);

            Console.WriteLine();

            // Remove the discovery exception.for the key 'myUrlKey'.
            myExceptionDictionary.Remove(myUrlKey);

            DiscoveryExceptionDictionary myNewExceptionDictionary =
                                       new DiscoveryExceptionDictionary();
            // Add an exception with the custom error message.
            Exception myNewException =
                 new Exception("The requested service is not available.");
            myNewExceptionDictionary.Add(myUrlKey, myNewException);
            myExceptionDictionary = myNewExceptionDictionary;

            Console.WriteLine("Added exceptions.");

            object[] myArray = new object[myExceptionDictionary.Count];
            myExceptionDictionary.Keys.CopyTo((Array)myArray,0);
            Console.WriteLine(" Keys are :");
            foreach(object myObj in myArray)
            {
               Console.WriteLine(" " + myObj.ToString());
            }

            Console.WriteLine();

            object[] myCollectionArray = new object[myExceptionDictionary.Count];
            myExceptionDictionary.Values.CopyTo((Array)myCollectionArray,0);
            Console.WriteLine(" Values are :");
            foreach(object myObj in myCollectionArray)
            {
               Console.WriteLine(" " + myObj.ToString());
            }
         }
      }
   }
}
Imports System.Web.Services.Discovery
Imports System.Xml
Imports System.Collections
Imports System.Runtime.Remoting
Imports System.Net

Public Class MySample
   
   Shared Sub Main()
      Dim myDiscoFile As String = "http://localhost/MathService_vb.disco"
      Dim myUrlKey As String = "http://localhost/MathService_vb.asmx?wsdl"
      Dim myDiscoveryClientProtocol1 As New DiscoveryClientProtocol()
      Dim myDiscoveryDocument As DiscoveryDocument = myDiscoveryClientProtocol1.Discover(myDiscoFile)
      Dim myEnumerator As IEnumerator = myDiscoveryDocument.References.GetEnumerator()
      While myEnumerator.MoveNext()
         Dim myContractReference As ContractReference = CType(myEnumerator.Current, ContractReference)
         Dim myDiscoveryClientProtocol2 As DiscoveryClientProtocol = myContractReference.ClientProtocol
         myDiscoveryClientProtocol2.ResolveAll()
         Dim myExceptionDictionary As DiscoveryExceptionDictionary = myDiscoveryClientProtocol2.Errors
         If myExceptionDictionary.Contains(myUrlKey) = True Then
            Console.WriteLine("'myExceptionDictionary' contains " + _
                 "a discovery exception for the key '" + myUrlKey + "'")
         Else
            Console.WriteLine("'myExceptionDictionary' does not contain" + _
                 " a discovery exception for the key '" + myUrlKey + "'")
         End If
         If myExceptionDictionary.Contains(myUrlKey) = True Then
            Console.WriteLine("System generated exceptions.")
            
            Dim myException As Exception = myExceptionDictionary(myUrlKey)
            Console.WriteLine(" Source : " + myException.Source)
            Console.WriteLine(" Exception : " + myException.Message)
            Console.WriteLine()
            
            ' Remove the discovery exception.for the key 'myUrlKey'.
            myExceptionDictionary.Remove(myUrlKey)
            Dim myNewExceptionDictionary As New DiscoveryExceptionDictionary()
            ' Add an exception with the custom error message.
            Dim myNewException As New Exception("The requested service is not available.")
            myNewExceptionDictionary.Add(myUrlKey, myNewException)
            myExceptionDictionary = myNewExceptionDictionary
            Console.WriteLine("Added exceptions.")
            
            Dim myArray(myExceptionDictionary.Count -1 ) As Object
            myExceptionDictionary.Keys.CopyTo(CType(myArray, Array), 0)
            Console.WriteLine(" Keys are :")
            Dim myObj As Object
            For Each myObj In  myArray
               Console.WriteLine(" " + myObj.ToString())
            Next myObj
            Console.WriteLine()
            
            Dim myCollectionArray(myExceptionDictionary.Count -1 ) As Object
            myExceptionDictionary.Values.CopyTo(CType(myCollectionArray, Array), 0)
            Console.WriteLine(" Values are :")
            For Each myObj In  myCollectionArray
               Console.WriteLine(" " + myObj.ToString())
            Next myObj
         End If 
      End While
   End Sub
End Class

注解

属性Errors的类型DiscoveryClientProtocolDiscoveryExceptionDictionary为 .

构造函数

DiscoveryExceptionDictionary()

初始化 DiscoveryExceptionDictionary 类的新实例。

属性

Count

获取 DictionaryBase 实例中包含的元素数。

(继承自 DictionaryBase)
Dictionary

获取 DictionaryBase 实例中包含的元素的列表。

(继承自 DictionaryBase)
InnerHashtable

获取 DictionaryBase 实例中包含的元素的列表。

(继承自 DictionaryBase)
Item[String]

获取或设置从 Exception 中发现指定的 URL 时发生的 DiscoveryExceptionDictionary

Keys

获取一个 ICollection 对象,它带有 DiscoveryExceptionDictionary 中的所有键。

Values

获取一个 ICollection 对象,它包含 DiscoveryExceptionDictionary 中的所有值。

方法

Add(String, Exception)

将带有 url 键的 Exception 添加到 DiscoveryExceptionDictionary

Clear()

清除 DictionaryBase 实例的内容。

(继承自 DictionaryBase)
Contains(String)

确定 DiscoveryExceptionDictionary 是否包含具有指定 URL 的 Exception

CopyTo(Array, Int32)

DictionaryBase 元素复制到位于指定索引处的一维 Array 中。

(继承自 DictionaryBase)
Equals(Object)

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

(继承自 Object)
GetEnumerator()

返回循环访问 IDictionaryEnumerator 实例的 DictionaryBase

(继承自 DictionaryBase)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnClear()

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

(继承自 DictionaryBase)
OnClearComplete()

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

(继承自 DictionaryBase)
OnGet(Object, Object)

获取 DictionaryBase 实例中带有指定键和值的元素。

(继承自 DictionaryBase)
OnInsert(Object, Object)

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

(继承自 DictionaryBase)
OnInsertComplete(Object, Object)

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

(继承自 DictionaryBase)
OnRemove(Object, Object)

当从 DictionaryBase 实例移除元素时执行其他自定义进程。

(继承自 DictionaryBase)
OnRemoveComplete(Object, Object)

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

(继承自 DictionaryBase)
OnSet(Object, Object, Object)

当在 DictionaryBase 实例中设置值之前执行其他自定义进程。

(继承自 DictionaryBase)
OnSetComplete(Object, Object, Object)

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

(继承自 DictionaryBase)
OnValidate(Object, Object)

在验证具有指定键和值的元素时执行其他自定义进程。

(继承自 DictionaryBase)
Remove(String)

Exception 中移除具有指定的 URL 的 DiscoveryExceptionDictionary

ToString()

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

(继承自 Object)

显式接口实现

ICollection.IsSynchronized

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

(继承自 DictionaryBase)
ICollection.SyncRoot

获取一个对象,该对象可用于同步对 DictionaryBase 对象的访问。

(继承自 DictionaryBase)
IDictionary.Add(Object, Object)

将带有指定键和值的元素添加到 DictionaryBase 中。

(继承自 DictionaryBase)
IDictionary.Contains(Object)

确定 DictionaryBase 是否包含特定键。

(继承自 DictionaryBase)
IDictionary.IsFixedSize

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

(继承自 DictionaryBase)
IDictionary.IsReadOnly

获取一个值,该值指示 DictionaryBase 对象是否为只读。

(继承自 DictionaryBase)
IDictionary.Item[Object]

获取或设置与指定的键关联的值。

(继承自 DictionaryBase)
IDictionary.Keys

获取包含 ICollection 对象中的键的 DictionaryBase 对象。

(继承自 DictionaryBase)
IDictionary.Remove(Object)

DictionaryBase 中移除带有指定键的元素。

(继承自 DictionaryBase)
IDictionary.Values

获取 ICollection 对象,它包含 DictionaryBase 对象中的值。

(继承自 DictionaryBase)
IEnumerable.GetEnumerator()

返回循环访问 IEnumeratorDictionaryBase

(继承自 DictionaryBase)

扩展方法

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

另请参阅