本文整理汇总了C#中System.Web.Services.Discovery.DiscoveryExceptionDictionary类的典型用法代码示例。如果您正苦于以下问题:C# DiscoveryExceptionDictionary类的具体用法?C# DiscoveryExceptionDictionary怎么用?C# DiscoveryExceptionDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryExceptionDictionary类属于System.Web.Services.Discovery命名空间,在下文中一共展示了DiscoveryExceptionDictionary类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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());
}
}
}
}
}