OperationBinding Class
Provides specifications for protocols and data formats for the messages used in the action supported by the XML Web service. This class cannot be inherited.
Assembly: System.Web.Services (in System.Web.Services.dll)
The OperationBinding class corresponds to the Web Services Description Language (WSDL) <operation> element enclosed by the <binding> element, which in turn corresponds to the Binding class. 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 OperationBinding class. It takes an existing ServiceDescription and adds support for the SOAP protocol.
#using <System.Xml.dll> #using <System.Web.Services.dll> #using <System.dll> using namespace System; using namespace System::Web::Services::Description; int main() { try { ServiceDescription^ myServiceDescription = ServiceDescription::Read( "MathService_input_cs.wsdl" ); String^ myTargetNamespace = myServiceDescription->TargetNamespace; // Create an OperationBinding for the Add operation. OperationBinding^ addOperationBinding = gcnew OperationBinding; String^ addOperation = "Add"; addOperationBinding->Name = addOperation; // Create an InputBinding for the Add operation. InputBinding^ myInputBinding = gcnew InputBinding; SoapBodyBinding^ mySoapBodyBinding = gcnew SoapBodyBinding; mySoapBodyBinding->Use = SoapBindingUse::Literal; myInputBinding->Extensions->Add( mySoapBodyBinding ); // Add the InputBinding to the OperationBinding. addOperationBinding->Input = myInputBinding; // Create an OutputBinding for the Add operation. OutputBinding^ myOutputBinding = gcnew OutputBinding; myOutputBinding->Extensions->Add( mySoapBodyBinding ); // Add the OutputBinding to the OperationBinding. addOperationBinding->Output = myOutputBinding; // Create an extensibility element for a SoapOperationBinding. SoapOperationBinding^ mySoapOperationBinding = gcnew SoapOperationBinding; mySoapOperationBinding->Style = SoapBindingStyle::Document; mySoapOperationBinding->SoapAction = String::Concat( myTargetNamespace, addOperation ); // Add the extensibility element SoapOperationBinding to // the OperationBinding. addOperationBinding->Extensions->Add( mySoapOperationBinding ); ServiceDescriptionFormatExtensionCollection^ myExtensions; // Get the FaultBindingCollection from the OperationBinding. FaultBindingCollection^ myFaultBindingCollection = addOperationBinding->Faults; FaultBinding^ myFaultBinding = gcnew FaultBinding; myFaultBinding->Name = "ErrorFloat"; // Associate SOAP fault binding to the fault binding of the operation. myExtensions = myFaultBinding->Extensions; SoapFaultBinding^ mySoapFaultBinding = gcnew SoapFaultBinding; mySoapFaultBinding->Use = SoapBindingUse::Literal; mySoapFaultBinding->Namespace = myTargetNamespace; myExtensions->Add( mySoapFaultBinding ); myFaultBindingCollection->Add( myFaultBinding ); // Get the BindingCollection from the ServiceDescription. BindingCollection^ myBindingCollection = myServiceDescription->Bindings; // Get the OperationBindingCollection of SOAP binding // from the BindingCollection. OperationBindingCollection^ myOperationBindingCollection = myBindingCollection[ 0 ]->Operations; myOperationBindingCollection->Add( addOperationBinding ); Console::WriteLine( "The operations supported by this service are:" ); System::Collections::IEnumerator^ myEnum = myOperationBindingCollection->GetEnumerator(); while ( myEnum->MoveNext() ) { OperationBinding^ myOperationBinding = safe_cast<OperationBinding^>(myEnum->Current); Binding^ myBinding = myOperationBinding->Binding; Console::WriteLine( " Binding : {0} :: Name of operation : {1}", myBinding->Name, myOperationBinding->Name ); FaultBindingCollection^ myFaultBindingCollection1 = myOperationBinding->Faults; System::Collections::IEnumerator^ myEnum1 = myFaultBindingCollection1->GetEnumerator(); while ( myEnum1->MoveNext() ) { FaultBinding^ myFaultBinding1 = safe_cast<FaultBinding^>(myEnum1->Current); Console::WriteLine( " Fault : {0}", myFaultBinding1->Name ); } } myServiceDescription->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 <System.dll>
using namespace System;
using namespace System::Web::Services::Description;
int main()
{
try
{
ServiceDescription* myServiceDescription =
ServiceDescription::Read(S"MathService_input_cs.wsdl");
String* myTargetNamespace = myServiceDescription->TargetNamespace;
// Create an OperationBinding for the Add operation.
OperationBinding* addOperationBinding = new OperationBinding();
String* addOperation = S"Add";
addOperationBinding->Name = addOperation;
// Create an InputBinding for the Add operation.
InputBinding* myInputBinding = new InputBinding();
SoapBodyBinding* mySoapBodyBinding = new SoapBodyBinding();
mySoapBodyBinding->Use = SoapBindingUse::Literal;
myInputBinding->Extensions->Add(mySoapBodyBinding);
// Add the InputBinding to the OperationBinding.
addOperationBinding->Input = myInputBinding;
// Create an OutputBinding for the Add operation.
OutputBinding* myOutputBinding = new OutputBinding();
myOutputBinding->Extensions->Add(mySoapBodyBinding);
// Add the OutputBinding to the OperationBinding.
addOperationBinding->Output = myOutputBinding;
// Create an extensibility element for a SoapOperationBinding.
SoapOperationBinding* mySoapOperationBinding =
new SoapOperationBinding();
mySoapOperationBinding->Style = SoapBindingStyle::Document;
mySoapOperationBinding->SoapAction = String::Concat( myTargetNamespace, addOperation );
// Add the extensibility element SoapOperationBinding to
// the OperationBinding.
addOperationBinding->Extensions->Add(mySoapOperationBinding);
ServiceDescriptionFormatExtensionCollection* myExtensions;
// Get the FaultBindingCollection from the OperationBinding.
FaultBindingCollection* myFaultBindingCollection =
addOperationBinding->Faults;
FaultBinding* myFaultBinding = new FaultBinding();
myFaultBinding->Name = S"ErrorFloat";
// Associate SOAP fault binding to the fault binding of the operation.
myExtensions = myFaultBinding->Extensions;
SoapFaultBinding* mySoapFaultBinding = new SoapFaultBinding();
mySoapFaultBinding->Use = SoapBindingUse::Literal;
mySoapFaultBinding->Namespace = myTargetNamespace;
myExtensions->Add(mySoapFaultBinding);
myFaultBindingCollection->Add(myFaultBinding);
// Get the BindingCollection from the ServiceDescription.
BindingCollection* myBindingCollection =
myServiceDescription->Bindings;
// Get the OperationBindingCollection of SOAP binding
// from the BindingCollection.
OperationBindingCollection* myOperationBindingCollection =
myBindingCollection->Item[0]->Operations;
myOperationBindingCollection->Add(addOperationBinding);
Console::WriteLine(
S"The operations supported by this service are:");
System::Collections::IEnumerator* myEnum = myOperationBindingCollection->GetEnumerator();
while (myEnum->MoveNext())
{
OperationBinding* myOperationBinding = __try_cast<OperationBinding*>(myEnum->Current);
Binding* myBinding = myOperationBinding->Binding;
Console::WriteLine(S" Binding : {0} :: Name of operation : {1}", myBinding->Name, myOperationBinding->Name);
FaultBindingCollection* myFaultBindingCollection1 =
myOperationBinding->Faults;
System::Collections::IEnumerator* myEnum1 = myFaultBindingCollection1->GetEnumerator();
while (myEnum1->MoveNext())
{
FaultBinding* myFaultBinding1 = __try_cast<FaultBinding*>(myEnum1->Current);
Console::WriteLine(S" Fault : {0}", myFaultBinding1->Name);
}
}
// Save the ServiceDescripition to an external file.
myServiceDescription->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.Web.Services.Description::DocumentableItem
System.Web.Services.Description::NamedItem
System.Web.Services.Description::OperationBinding
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.