当前位置: 首页>>代码示例>>C#>>正文


C# OperationFaultCollection类代码示例

本文整理汇总了C#中System.Web.Services.Description.OperationFaultCollection的典型用法代码示例。如果您正苦于以下问题:C# OperationFaultCollection类的具体用法?C# OperationFaultCollection怎么用?C# OperationFaultCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OperationFaultCollection类属于System.Web.Services.Description命名空间,在下文中一共展示了OperationFaultCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Web.Services.Description;

public class MyOperationFaultCollectionSample
{
   public static void Main()
   {
      try
      {
         // Read the StockQuote.wsdl file as input.
         ServiceDescription myServiceDescription = 
            ServiceDescription.Read("StockQuote_cs.wsdl");
         PortTypeCollection myPortTypeCollection = 
            myServiceDescription.PortTypes;
         PortType myPortType = myPortTypeCollection[0];
         OperationCollection myOperationCollection = myPortType.Operations;
         Operation myOperation = myOperationCollection[0];
         OperationFaultCollection myOperationFaultCollection = 
            myOperation.Faults;

         // Reverse the operation fault order.
         if(myOperationFaultCollection.Count > 1)
         {
            OperationFault myOperationFault = myOperationFaultCollection[0];
            OperationFault[] myOperationFaultArray = 
               new OperationFault[myOperationFaultCollection.Count];

            // Copy the operation faults to a temporary array.
            myOperationFaultCollection.CopyTo(myOperationFaultArray, 0);

            // Remove all the operation faults from the collection.
            for(int i = 0; i < myOperationFaultArray.Length; i++)
            {
               myOperationFaultCollection.Remove(myOperationFaultArray[i]);
            }

            // Insert the operation faults in the reverse order.
            for(int i = 0, j = (myOperationFaultArray.Length - 1);
               i < myOperationFaultArray.Length; i++, j--)
            {
               myOperationFaultCollection.Insert(
                  i, myOperationFaultArray[j]);
            }
            if ( myOperationFaultCollection.Contains(myOperationFault) &&
               (myOperationFaultCollection.IndexOf(myOperationFault) 
               == myOperationFaultCollection.Count-1))
            {
               Console.WriteLine(
                  "Succeeded in reversing the operation faults.");
            }
            else 
            {
               Console.WriteLine("Error while reversing the faults.");
            }
         }
         BindingCollection myBindingCollection = 
            myServiceDescription.Bindings;
         Binding myBinding = myBindingCollection[0];
         OperationBindingCollection myOperationBindingCollection = 
            myBinding.Operations;
         OperationBinding myOperationBinding = 
            myOperationBindingCollection[0];
         FaultBindingCollection myFaultBindingCollection = 
            myOperationBinding.Faults;

         // Reverse the fault binding order.
         if(myFaultBindingCollection.Count > 1) 
         {
            FaultBinding myFaultBinding = myFaultBindingCollection[0];

            FaultBinding[] myFaultBindingArray = 
               new FaultBinding[myFaultBindingCollection.Count];

            // Copy the fault bindings to a temporary array.
            myFaultBindingCollection.CopyTo(myFaultBindingArray, 0);

            // Remove all the fault bindings.
            for(int i = 0; i < myFaultBindingArray.Length; i++)
            {
               myFaultBindingCollection.Remove(myFaultBindingArray[i]);
            }

            // Insert the fault bindings in the reverse order.
            for(int i = 0, j = (myFaultBindingArray.Length - 1);
               i < myFaultBindingArray.Length; i++, j--)
            {
               myFaultBindingCollection.Insert(i, myFaultBindingArray[j]);
            }

            // Check whether the first element before the reversal 
            // is now the last element.
            if(myFaultBindingCollection.Contains(myFaultBinding) && 
               myFaultBindingCollection.IndexOf(myFaultBinding) == 
               (myFaultBindingCollection.Count - 1))
            {
               // Write the WSDL generated to a file.
               myServiceDescription.Write("StockQuoteOut_cs.wsdl");
               Console.WriteLine(
                  "The file StockQuoteOut_cs.wsdl was successfully written.");
            }
            else
            {
               Console.WriteLine(
                  "An error occurred while reversing the input WSDL file.");
            }
         }
      }
      catch(Exception e)
      {
         Console.WriteLine("Exception caught!!!");
         Console.WriteLine("Source : " + e.Source);
         Console.WriteLine("Message : " + e.Message);
      }
   }
}
开发者ID:.NET开发者,项目名称:System.Web.Services.Description,代码行数:116,代码来源:OperationFaultCollection


注:本文中的System.Web.Services.Description.OperationFaultCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。