OperationCollection Class
Represents a collection of instances of the Operation class. This class cannot be inherited.
Assembly: System.Web.Services (in System.Web.Services.dll)
The Operation class corresponds to the Web Services Description Language (WSDL) <operation> element enclosed by the <portType> element. For more information about WSDL, see the specification at http://www.w3.org/TR/wsdl/.
The following example demonstrates the use of the properties and methods exposed by the OperationCollection class.
#using <System.dll> #using <System.Xml.dll> #using <System.Web.Services.dll> using namespace System; using namespace System::Web::Services; using namespace System::Xml; using namespace System::Web::Services::Description; int main() { try { // Read the 'MathService_Input_cs.wsdl' file. ServiceDescription^ myDescription = ServiceDescription::Read( "MathService_Input_cs.wsdl" ); PortTypeCollection^ myPortTypeCollection = myDescription->PortTypes; // Get the 'OperationCollection' for 'SOAP' protocol. OperationCollection^ myOperationCollection = myPortTypeCollection[ 0 ]->Operations; Operation^ myOperation = gcnew Operation; myOperation->Name = "Add"; OperationMessage^ myOperationMessageInput = (OperationMessage^)(gcnew OperationInput); myOperationMessageInput->Message = gcnew XmlQualifiedName( "AddSoapIn",myDescription->TargetNamespace ); OperationMessage^ myOperationMessageOutput = (OperationMessage^)(gcnew OperationOutput); myOperationMessageOutput->Message = gcnew XmlQualifiedName( "AddSoapOut",myDescription->TargetNamespace ); myOperation->Messages->Add( myOperationMessageInput ); myOperation->Messages->Add( myOperationMessageOutput ); myOperationCollection->Add( myOperation ); if ( myOperationCollection->Contains( myOperation ) == true ) { Console::WriteLine( "The index of the added 'myOperation' operation is : {0}", myOperationCollection->IndexOf( myOperation ) ); } myOperationCollection->Remove( myOperation ); // Insert the 'myOpearation' operation at the index '0'. myOperationCollection->Insert( 0, myOperation ); Console::WriteLine( "The operation at index '0' is : {0}", myOperationCollection[ 0 ]->Name ); array<Operation^>^myOperationArray = gcnew array<Operation^>(myOperationCollection->Count); myOperationCollection->CopyTo( myOperationArray, 0 ); Console::WriteLine( "The operation(s) in the collection are :" ); for ( int i = 0; i < myOperationCollection->Count; i++ ) { Console::WriteLine( " {0}", myOperationArray[ i ]->Name ); } myDescription->Write( "MathService_New_cs.wsdl" ); } catch ( Exception^ e ) { Console::WriteLine( "Exception caught!!!" ); Console::WriteLine( "Source : {0}", e->Source ); Console::WriteLine( "Message : {0}", e->Message ); } }
#using <mscorlib.dll>
#using <System.Xml.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Web::Services;
using namespace System::Xml;
using namespace System::Web::Services::Description;
int main()
{
try
{
// Read the 'MathService_Input_cs.wsdl' file.
ServiceDescription* myDescription =
ServiceDescription::Read(S"MathService_Input_cs.wsdl");
PortTypeCollection* myPortTypeCollection =myDescription->PortTypes;
// Get the 'OperationCollection' for 'SOAP' protocol.
OperationCollection* myOperationCollection =
myPortTypeCollection->Item[0]->Operations;
Operation* myOperation = new Operation();
myOperation->Name = S"Add";
OperationMessage* myOperationMessageInput =
dynamic_cast<OperationMessage*> (new OperationInput());
myOperationMessageInput->Message = new XmlQualifiedName
(S"AddSoapIn",myDescription->TargetNamespace);
OperationMessage* myOperationMessageOutput =
dynamic_cast<OperationMessage*> (new OperationOutput());
myOperationMessageOutput->Message = new XmlQualifiedName(
S"AddSoapOut",myDescription->TargetNamespace);
myOperation->Messages->Add(myOperationMessageInput);
myOperation->Messages->Add(myOperationMessageOutput);
myOperationCollection->Add(myOperation);
if(myOperationCollection->Contains(myOperation) == true)
{
Console::WriteLine(S"The index of the added 'myOperation' operation is : {0}",
__box(myOperationCollection->IndexOf(myOperation)));
}
myOperationCollection->Remove(myOperation);
// Insert the 'myOpearation' operation at the index '0'.
myOperationCollection->Insert(0, myOperation);
Console::WriteLine(S"The operation at index '0' is : {0}", myOperationCollection->Item[0]->Name);
Operation* myOperationArray[] = new Operation*[myOperationCollection->Count];
myOperationCollection->CopyTo(myOperationArray, 0);
Console::WriteLine(S"The operation(s) in the collection are :");
for(int i = 0; i < myOperationCollection->Count; i++)
{
Console::WriteLine(S" {0}", myOperationArray[i]->Name);
}
myDescription->Write(S"MathService_New_cs.wsdl");
}
catch(Exception* e)
{
Console::WriteLine(S"Exception caught!!!");
Console::WriteLine(S"Source : {0}", e->Source);
Console::WriteLine(S"Message : {0}", e->Message);
}
}
System.Collections::CollectionBase
System.Web.Services.Description::ServiceDescriptionBaseCollection
System.Web.Services.Description::OperationCollection
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.