Прочетете на английски Редактиране

Споделяне чрез


Service.Extensions Property

Definition

Gets the collection of extensibility elements associated with the Service.

C#
public System.Web.Services.Description.ServiceDescriptionFormatExtensionCollection Extensions { get; }
C#
public override System.Web.Services.Description.ServiceDescriptionFormatExtensionCollection Extensions { get; }

Property Value

The collection of extensibility elements associated with the Service.

Examples

C#
ServiceDescription myServiceDescription =
   ServiceDescription.Read("MathService_CS.wsdl");
ServiceCollection myServiceCollection =
   myServiceDescription.Services;

int noOfServices = myServiceCollection.Count;
Console.WriteLine("\nTotal number of services: " + noOfServices);

// Get a reference to the service.
Service myOldService = myServiceCollection[0];
Console.WriteLine("No. of Ports in the Service" +
   myServiceCollection[0].Ports.Count);
Console.WriteLine("These are the ports in the service:");
for(int i = 0; i < myOldService.Ports.Count; i++)
   Console.WriteLine("Port name: " + myOldService.Ports[i].Name);
Console.WriteLine("Service name: " + myOldService.Name);

Service  myService = new Service();
myService.Name = "MathService";

// Add the ports to the newly created service.
for(int i = 0; i < myOldService.Ports.Count; i++)
{
   string PortName = myServiceCollection[0].Ports[i].Name;
   string BindingName =
      myServiceCollection[0].Ports[i].Binding.Name;
   myService.Ports.Add(CreatePort(PortName, BindingName,
      myServiceDescription.TargetNamespace));
}

Console.WriteLine("Newly created ports -");
for(int i = 0; i < myService.Ports.Count; i++)
   Console.WriteLine("Port Name: " + myOldService.Ports[i].Name);

// Add the extensions to the newly created service.
int noOfExtensions = myOldService.Extensions.Count;
Console.WriteLine("No. of extensions: " + noOfExtensions);
if (noOfExtensions > 0)
{
   for(int i = 0; i <myOldService.Ports.Count; i++)
      myService.Extensions.Add(
         myServiceCollection[0].Extensions[i]);
}

// Remove the service from the collection.
myServiceCollection.Remove(myOldService);

// Add the newly created service.
myServiceCollection.Add(myService);
myServiceDescription.Write("MathService_New.wsdl");

Applies to

Продукт Версии
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)