Freigeben über


ServiceCollection.Insert(Int32, Service) Methode

Definition

Fügt der Service die angegebene ServiceCollection-Instanz am angegebenen nullbasierten Index hinzu.

public:
 void Insert(int index, System::Web::Services::Description::Service ^ service);
public void Insert (int index, System.Web.Services.Description.Service service);
member this.Insert : int * System.Web.Services.Description.Service -> unit
Public Sub Insert (index As Integer, service As Service)

Parameter

index
Int32

Der nullbasierte Index, an dem der service-Parameter eingefügt werden soll.

service
Service

Der der Auflistung hinzuzufügende Service.

Ausnahmen

Die index-Parameter ist kleiner als 0 (null).

- oder -

Der index-Parameter ist größer als Count.

Beispiele

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.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);
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)

Hinweise

Wenn die Anzahl der Elemente in der Auflistung bereits der Kapazität der Auflistung entspricht, wird die Kapazität verdoppelt, indem das interne Array vor dem Einfügen des neuen Elements automatisch neu zugeordnet wird.

Wenn der Wert des index Parameters gleich ist, Countwird der service Parameter am Ende von ServiceCollectionhinzugefügt.

Die Elemente nach der Einfügemarke werden nach unten verschoben, um das neue Element aufzunehmen.

Gilt für: