This documentation is archived and is not being maintained.
ServiceCollection.Add Method
.NET Framework 1.1
Adds the specified Service to the end of the ServiceCollection.
[Visual Basic] Public Function Add( _ ByVal service As Service _ ) As Integer [C#] public int Add( Service service ); [C++] public: int Add( Service* service ); [JScript] public function Add( service : Service ) : int;
Parameters
- service
- The Service instance to add to the collection.
Return Value
The zero-based index where the service parameter has been added.
Example
[Visual Basic] ' Build a new Service. 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/ServiceCollection_Item/AddSub.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/ServiceCollection_Item/AddSub.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. myServiceCollection.Add(myService) [C#] // Build a new Service. 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/ServiceCollection_Item/AddSub_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/ServiceCollection_Item/AddSub_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. myServiceCollection .Add(myService); [C++] // Build a new Service. 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/ServiceCollection_Item/AddSub_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/ServiceCollection_Item/AddSub_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. myServiceCollection ->Add(myService);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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: