DiscoveryExceptionDictionary 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
收集 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
- 繼承
範例
#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的 DiscoveryClientProtocol 屬性的類型為 DiscoveryExceptionDictionary 。
建構函式
DiscoveryExceptionDictionary() |
初始化 DiscoveryExceptionDictionary 類別的新執行個體。 |
屬性
Count |
取得 DictionaryBase 執行個體中包含的元素數目。 (繼承來源 DictionaryBase) |
Dictionary |
取得包含於 DictionaryBase 執行個體中的項目清單。 (繼承來源 DictionaryBase) |
InnerHashtable |
取得包含於 DictionaryBase 執行個體中的項目清單。 (繼承來源 DictionaryBase) |
Item[String] |
取得或設定從 Exception 探索指定的 URL 時所發生的 DiscoveryExceptionDictionary。 |
Keys |
取得具有 ICollection 中所有索引鍵的 DiscoveryExceptionDictionary 物件。 |
Values |
取得 ICollection 物件,包含在 DiscoveryExceptionDictionary 中所有數值。 |
方法
明確介面實作
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() |
傳回透過 IEnumerator 重複的 DictionaryBase。 (繼承來源 DictionaryBase) |
擴充方法
Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
OfType<TResult>(IEnumerable) |
根據指定的型別來篩選 IEnumerable 的項目。 |
AsParallel(IEnumerable) |
啟用查詢的平行化作業。 |
AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |