Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DiscoveryExceptionDictionary Class

Collects exceptions that occurred during XML Web services discovery. This class cannot be inherited.

Namespace:  System.Web.Services.Discovery
Assembly:  System.Web.Services (in System.Web.Services.dll)

public sealed class DiscoveryExceptionDictionary : DictionaryBase

The Errors property of DiscoveryClientProtocol is of type DiscoveryExceptionDictionary.

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());
            }
         }
      }
   }
}
#using <mscorlib.dll>
#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 = S"http://localhost/MathService_cs.disco";
   String* myUrlKey = S"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 =
         dynamic_cast<ContractReference*>(myEnumerator->Current);
      DiscoveryClientProtocol* myDiscoveryClientProtocol2 =
         myContractReference->ClientProtocol;
      myDiscoveryClientProtocol2->ResolveAll();
      DiscoveryExceptionDictionary* myExceptionDictionary
         = myDiscoveryClientProtocol2->Errors;
      if ( myExceptionDictionary->Contains(myUrlKey) == true )
      {
         Console::WriteLine(S"'myExceptionDictionary' contains a discovery exception for the key '{0}'", myUrlKey );
      }
      else
      {
         Console::WriteLine(S"'myExceptionDictionary' does not contain a discovery exception for the key '{0}'", myUrlKey );
      }
      if (myExceptionDictionary->Contains(myUrlKey) == true )
      {
         Console::WriteLine(S"System generated exceptions.");

         Exception* myException = myExceptionDictionary->Item[myUrlKey];
         Console::WriteLine(S" Source : {0}", myException->Source);
         Console::WriteLine(S" Exception : {0}", 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(S"The requested service is not available.");
         myNewExceptionDictionary->Add(myUrlKey, myNewException);
         myExceptionDictionary = myNewExceptionDictionary;

         Console::WriteLine(S"Added exceptions.");

         Object* myArray[] = new Object*[myExceptionDictionary->Count];
         myExceptionDictionary->Keys->CopyTo((Array*)myArray,0);
         Console::WriteLine(S" Keys are :");
         IEnumerator* myEnum = myArray->GetEnumerator();
         while (myEnum->MoveNext())
         {
            Object* myObj = __try_cast<Object*>(myEnum->Current);
            Console::WriteLine(S" {0}", myObj);
         }

         Console::WriteLine();

         Object* myCollectionArray[] = new Object*[myExceptionDictionary->Count];
         myExceptionDictionary->Values->CopyTo((Array*)myCollectionArray,0);
         Console::WriteLine(S" Values are :");
         IEnumerator* myEnum1 = myCollectionArray->GetEnumerator();
         while (myEnum1->MoveNext())
         {
            Object* myObj = __try_cast<Object*>(myEnum1->Current);
            Console::WriteLine(S" {0}", myObj);
         }
      }
   }
}

System.Object
  System.Collections.DictionaryBase
    System.Web.Services.Discovery.DiscoveryExceptionDictionary

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft