共用方式為


ServiceCollection.Insert(Int32, Service) 方法

定義

加入指定的 Service 執行個體至 ServiceCollection,於指定的以零起始的索引位置。

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)

參數

index
Int32

以零起始的索引,service 參數要在此處插入。

service
Service

要加入至集合的 Service

例外狀況

index 參數小於零。

-或- index 參數大於 Count

範例

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)

備註

如果集合中的專案數目已經等於集合的容量,則會在插入新元素之前自動重新配置內部陣列,將容量加倍。

如果 參數的值 index 等於 ,參數 service 就會加入 至 的 ServiceCollection Count 結尾。

插入點後的專案會向下移動以容納新的元素。

適用於