This documentation is archived and is not being maintained.

ServiceCollection.Insert Method

Adds the specified Service instance to the ServiceCollection at the specified zero-based index.

[Visual Basic]
Public Sub Insert( _
   ByVal index As Integer, _
   ByVal service As Service _
)
[C#]
public void Insert(
 int index,
 Service service
);
[C++]
public: void Insert(
 int index,
 Service* service
);
[JScript]
public function Insert(
   index : int,
 service : Service
);

Parameters

index
The zero-based index at which to insert the service parameter.
service
The Service to add to the collection.

Exceptions

Exception Type Condition
IndexOutOfRangeException The index parameter is less than zero.

- or -

The index parameter is greater than Count.

Remarks

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.

Example

[Visual Basic] 
Dim myService As New Service()
myService.Name = "MathService"
Dim myXmlQualifiedName As New XmlQualifiedName("s0:MathServiceSoap")

' Build a new Port for SOAP.
Dim mySoapPort As New Port()
mySoapPort.Name = "MathServiceSoap"
mySoapPort.Binding = myXmlQualifiedName
Dim mySoapAddressBinding As New SoapAddressBinding()
mySoapAddressBinding.Location = _
   "http://localhost/ServiceDescription_Read/AddService_VB.asmx"
mySoapPort.Extensions.Add(mySoapAddressBinding)

' Build a new Port for HTTP-GET.
Dim myXmlQualifiedName2 As New _
   XmlQualifiedName("s0:MathServiceHttpGet")
Dim myHttpGetPort As New Port()
myHttpGetPort.Name = "MathServiceHttpGet"
myHttpGetPort.Binding = myXmlQualifiedName2
Dim myHttpAddressBinding As New HttpAddressBinding()
myHttpAddressBinding.Location = _
   "http://localhost/ServiceDescription_Read/AddService_VB.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)

[C#] 
Service myService = new Service();
myService.Name = "MathService";
XmlQualifiedName myXmlQualifiedName = 
   new XmlQualifiedName("s0:MathServiceSoap");

// Build a new Port for SOAP.
Port mySoapPort = new Port();
mySoapPort.Name = "MathServiceSoap";
mySoapPort.Binding = myXmlQualifiedName;
SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();
mySoapAddressBinding.Location =
   "http://localhost/ServiceDescription_Read/AddService_CS.asmx";
mySoapPort.Extensions.Add(mySoapAddressBinding);

// Build a new Port for HTTP-GET.
XmlQualifiedName myXmlQualifiedName2 = 
   new XmlQualifiedName("s0:MathServiceHttpGet");
Port myHttpGetPort = new Port();
myHttpGetPort.Name = "MathServiceHttpGet";
myHttpGetPort.Binding = myXmlQualifiedName2;
HttpAddressBinding myHttpAddressBinding = new 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);

[C++] 
Service* myService = new Service();
myService->Name = S"MathService";
XmlQualifiedName* myXmlQualifiedName = 
   new XmlQualifiedName(S"s0:MathServiceSoap");

// Build a new Port for SOAP.
Port* mySoapPort = new Port();
mySoapPort->Name = S"MathServiceSoap";
mySoapPort->Binding = myXmlQualifiedName;
SoapAddressBinding* mySoapAddressBinding = new SoapAddressBinding();
mySoapAddressBinding->Location =
   S"http://localhost/ServiceDescription_Read/AddService_CS.asmx";
mySoapPort->Extensions->Add(mySoapAddressBinding);

// Build a new Port for HTTP-GET.
XmlQualifiedName* myXmlQualifiedName2 = 
   new XmlQualifiedName(S"s0:MathServiceHttpGet");
Port* myHttpGetPort = new Port();
myHttpGetPort->Name = S"MathServiceHttpGet";
myHttpGetPort->Binding = myXmlQualifiedName2;
HttpAddressBinding* myHttpAddressBinding = new HttpAddressBinding();
myHttpAddressBinding->Location = 
   S"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);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ServiceCollection Class | ServiceCollection Members | System.Web.Services.Description Namespace

Show: