ServiceCollection.Insert Method
Assembly: System.Web.Services (in system.web.services.dll)
public void Insert ( int index, Service service )
public function Insert ( index : int, service : Service )
Not applicable.
Parameters
- index
The zero-based index at which to insert the service parameter.
- service
The Service to add to the collection.
| Exception type | Condition |
|---|---|
|
The index parameter is less than zero. - or - The index parameter is greater than Count. |
If the number of items in the collection already equals the collection's capacity, the capacity is doubled by automatically reallocating the internal array before the new element is inserted.
If the value of the index parameter is equal to Count, the service parameter is added to the end of the ServiceCollection.
The elements after the insertion point move down to accommodate the new element.
Service^ myService = gcnew Service; myService->Name = "MathService"; XmlQualifiedName^ myXmlQualifiedName = gcnew XmlQualifiedName( "s0:MathServiceSoap" ); // Build a new Port for SOAP. Port^ mySoapPort = gcnew Port; mySoapPort->Name = "MathServiceSoap"; mySoapPort->Binding = myXmlQualifiedName; SoapAddressBinding^ mySoapAddressBinding = gcnew SoapAddressBinding; mySoapAddressBinding->Location = "http://localhost/ServiceDescription_Read/AddService_CS.asmx"; mySoapPort->Extensions->Add( mySoapAddressBinding ); // Build a new Port for HTTP-GET. XmlQualifiedName^ myXmlQualifiedName2 = gcnew XmlQualifiedName( "s0:MathServiceHttpGet" ); Port^ myHttpGetPort = gcnew Port; myHttpGetPort->Name = "MathServiceHttpGet"; myHttpGetPort->Binding = myXmlQualifiedName2; HttpAddressBinding^ myHttpAddressBinding = gcnew HttpAddressBinding; myHttpAddressBinding->Location = "http://localhost/ServiceDescription_Read/AddService_CS.asmx"; myHttpGetPort->Extensions->Add( myHttpAddressBinding ); // Add the ports to the service. myService->Ports->Add( myHttpGetPort ); myService->Ports->Add( mySoapPort ); // Add the service to the ServiceCollection. myServiceDescription->Services->Insert( 1, myService );
Service myService = new Service();
myService.set_Name("MathService");
XmlQualifiedName myXmlQualifiedName =
new XmlQualifiedName("s0:MathServiceSoap");
// Build a new Port for SOAP.
Port mySoapPort = new Port();
mySoapPort.set_Name("MathServiceSoap");
mySoapPort.set_Binding(myXmlQualifiedName);
SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();
mySoapAddressBinding.set_Location(
"http://localhost/ServiceDescription_Read/AddService_JSL.asmx");
mySoapPort.get_Extensions().Add(mySoapAddressBinding);
// Build a new Port for HTTP-GET.
XmlQualifiedName myXmlQualifiedName2 =
new XmlQualifiedName("s0:MathServiceHttpGet");
Port myHttpGetPort = new Port();
myHttpGetPort.set_Name("MathServiceHttpGet");
myHttpGetPort.set_Binding(myXmlQualifiedName2);
HttpAddressBinding myHttpAddressBinding = new HttpAddressBinding();
myHttpAddressBinding.set_Location(
"http://localhost/ServiceDescription_Read/AddService_JSL.asmx");
myHttpGetPort.get_Extensions().Add(myHttpAddressBinding);
// Add the ports to the service.
myService.get_Ports().Add(myHttpGetPort);
myService.get_Ports().Add(mySoapPort);
// Add the service to the ServiceCollection.
myServiceDescription.get_Services().Insert(1, myService);
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.