Export (0) Print
Expand All

ServiceEndpointCollection Class

A collection that contains the endpoints for a service.

System.Object
  System.Collections.ObjectModel.Collection(Of ServiceEndpoint)
    System.ServiceModel.Description.ServiceEndpointCollection

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

'Declaration
Public Class ServiceEndpointCollection _
	Inherits Collection(Of ServiceEndpoint)

The ServiceEndpointCollection type exposes the following members.

  NameDescription
Public propertyCountGets the number of elements actually contained in the Collection(Of T). (Inherited from Collection(Of T).)
Public propertyItemGets or sets the element at the specified index. (Inherited from Collection(Of T).)
Protected propertyItemsGets a IList(Of T) wrapper around the Collection(Of T). (Inherited from Collection(Of T).)
Top

  NameDescription
Public methodAddAdds an object to the end of the Collection(Of T). (Inherited from Collection(Of T).)
Public methodClearRemoves all elements from the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodClearItemsRemoves all elements from the Collection(Of T). (Inherited from Collection(Of T).)
Public methodContainsDetermines whether an element is in the Collection(Of T). (Inherited from Collection(Of T).)
Public methodCopyToCopies the entire Collection(Of T) to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from Collection(Of T).)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFind(Type)Returns the first service endpoint found that satisfies the specified contract type from the collection of service endpoints.
Public methodFind(Uri)Returns a service endpoint with a specified address from the collection of service endpoints.
Public methodFind(XmlQualifiedName)Returns a service endpoint with a specified namespace and contract name from the collection of service endpoints.
Public methodFind(Type, XmlQualifiedName)Returns a service endpoint of a specified contract type and with a specified binding name and namespace from the collection of service endpoints.
Public methodFind(XmlQualifiedName, XmlQualifiedName)Returns the first service endpoint with the specified contract name and namespace and binding name and namespace from the collection of service endpoints.
Public methodFindAll(Type)Returns a collection of all the service endpoints for a specified type of service.
Public methodFindAll(XmlQualifiedName)Returns a collection of all the service endpoints for a specified service name.
Public methodGetEnumeratorReturns an enumerator that iterates through the Collection(Of T). (Inherited from Collection(Of T).)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOfSearches for the specified object and returns the zero-based index of the first occurrence within the entire Collection(Of T). (Inherited from Collection(Of T).)
Public methodInsertInserts an element into the Collection(Of T) at the specified index. (Inherited from Collection(Of T).)
Protected methodInsertItemInserts an item into the collection at the specified index. (Overrides Collection(Of T).InsertItem(Int32, T).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves the first occurrence of a specific object from the Collection(Of T). (Inherited from Collection(Of T).)
Public methodRemoveAtRemoves the element at the specified index of the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodRemoveItemRemoves the element at the specified index of the Collection(Of T). (Inherited from Collection(Of T).)
Protected methodSetItemReplaces the element in the collection at the specified index. (Overrides Collection(Of T).SetItem(Int32, T).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToCopies the elements of the ICollection to an Array, starting at a particular Array index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection(Of T).IsReadOnlyGets a value indicating whether the ICollection(Of T) is read-only. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value indicating whether access to the ICollection is synchronized (thread safe). (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to the ICollection. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that iterates through a collection. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.AddAdds an item to the IList. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.ContainsDetermines whether the IList contains a specific value. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.IndexOfDetermines the index of a specific item in the IList. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.InsertInserts an item into the IList at the specified index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.IsFixedSizeGets a value indicating whether the IList has a fixed size. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.IsReadOnlyGets a value indicating whether the IList is read-only. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate propertyIList.ItemGets or sets the element at the specified index. (Inherited from Collection(Of T).)
Explicit interface implemetationPrivate methodIList.RemoveRemoves the first occurrence of a specific object from the IList. (Inherited from Collection(Of T).)
Top

This collection of endpoints for a service is used by the metadata API to manage services with multiple endpoints. ServiceEndpointCollection is returned, for example, by the Endpoints property and by the ImportAllEndpoints method when creating service endpoints from WSDL port types.

The collection provides the functionality to Find the endpoints of a particular type, that have a specific name or address, or to FindAll of the endpoints for a service that meet a specified contract type or name criteria.

The following example illustrates the use of the Find and FindAll methods to enumerate ServiceEndpoint objects that satisfy various search criteria.


[System.ServiceModel.ServiceContractAttribute(
    Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface IAdd
{

	[System.ServiceModel.OperationContractAttribute(
        Action = "http://Microsoft.ServiceModel.Samples/IAdd/Add", 
        ReplyAction = "http://Microsoft.ServiceModel.Samples/IAdd/AddResponse")]
	double Add(double n1, double n2);

}

public interface IAddChannel : IAdd, System.ServiceModel.IClientChannel
{
}

public partial class AddClient : System.ServiceModel.ClientBase<IAdd>, IAdd
{

	public AddClient()
	{
	}

	public AddClient(string endpointConfigurationName)
		:
			base(endpointConfigurationName)
	{
	}

    public AddClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress address)
		:
			base(binding, address)
	{
	}

	public double Add(double n1, double n2)
	{
		return base.Channel.Add(n1, n2);
	}

}
using System;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Xml;

namespace Microsoft.ServiceModel.Samples
{
    // Define an add service contract.
    [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
    public interface IAdd
    {
        [OperationContract]
        double Add(double n1, double n2);

    }

    // Implement the add service contract. 
    public class AddService : IAdd
    {
        public double Add(double n1, double n2)
        {
            double result = n1 + n2;
            Console.WriteLine("Received Add({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        // Host the add service within an EXE console application. 
        public static void Main()
        {
            // Set addresses for the service from configuration.
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

            // Create a ServiceHost for the AddService type at the addAdddress.
            ServiceHost serviceHost = new ServiceHost(typeof(AddService), baseAddress);

            // Enumerate endpoints (defined in the App.config file).
                Console.WriteLine("All endpoints for the service:");
		ServiceDescription desc = serviceHost.Description;
		foreach (ServiceEndpoint endpoint in desc.Endpoints)
                {
                    Console.WriteLine("Endpoint - address:  {0}", endpoint.Address);
                    Console.WriteLine("           binding:  {0}", endpoint.Binding.Name);
                    Console.WriteLine("           contract: {0}", endpoint.Contract.Name);
                    Console.WriteLine();
                }

             // Find a service endpoint using the base address.
                ServiceEndpoint baseEndpoint = desc.Endpoints.Find(baseAddress);
                Console.WriteLine("A service endpoint at the base address:");
                Console.WriteLine("Endpoint - address:  {0}", baseEndpoint.Address);
                Console.WriteLine("           binding name:  {0}", baseEndpoint.Binding.Name);
                Console.WriteLine("           contract name: {0}", baseEndpoint.Contract.Name);
                Console.WriteLine();

             // Find an endpoint for the IAdd type of service.
                ServiceEndpoint addEndpoint = desc.Endpoints.Find(typeof(IAdd));
                Console.WriteLine("A service endpoint of the IAdd type:");
                Console.WriteLine("Endpoint - address:  {0}", addEndpoint.Address);
                Console.WriteLine("           binding name:  {0}", addEndpoint.Binding.Name);
                Console.WriteLine("           contract name: {0}", addEndpoint.Contract.Name);
                Console.WriteLine();

             // Find all of the endpoints for the IAdd type of service.
                Collection<ServiceEndpoint> addEndpoints = desc.Endpoints.FindAll(typeof(IAdd));
                Console.WriteLine("All the endpoints for the service of the IAdd type:");
                foreach (ServiceEndpoint endpoint in addEndpoints)
                {
                    Console.WriteLine("Endpoint - address:  {0}", endpoint.Address);
                    Console.WriteLine("           binding name:  {0}", endpoint.Binding.Name);
                    Console.WriteLine("           contract name: {0}", endpoint.Contract.Name);
                    Console.WriteLine();
                }

             // Find all of the endpoints for the service with the specific qualified contract name.
                XmlQualifiedName contractQName = new XmlQualifiedName("IAdd","http://Microsoft.ServiceModel.Samples");
                Collection<ServiceEndpoint> contractEndpoints = desc.Endpoints.FindAll(contractQName);
                Console.WriteLine("All endpoints for the service with the contract QName\n\t http://Microsoft.ServiceModel.Samples.IAdd");

                foreach (ServiceEndpoint endpoint in contractEndpoints)
                {
                    Console.WriteLine("Endpoint - address:  {0}", endpoint.Address);
                    Console.WriteLine("           binding name:  {0}", endpoint.Binding.Name);
                    Console.WriteLine("           contract name: {0}", endpoint.Contract.Name);
                    Console.WriteLine("           contract namespace: {0}", endpoint.Contract.Namespace);
                    Console.WriteLine();
                }

             // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();


             // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.ReadLine();

             // Close the ServiceHostBase to shutdown the service.
                serviceHost.Close();
        }
    }
}

/* This code produces the following output:

All endpoints for the service:
Endpoint - address:  http://localhost:8000/samples/service
           binding:  WSHttpBinding
           contract: IAdd

Endpoint - address:  net.tcp://localhost:9000/samples/service
           binding:  NetTcpBinding
           contract: IAdd

A service endpoint at the base address:
Endpoint - address:  http://localhost:8000/samples/service
           binding name:  WSHttpBinding
           contract name: IAdd

A service endpoint of the IAdd type:
Endpoint - address:  http://localhost:8000/samples/service
           binding name:  WSHttpBinding
           contract name: IAdd

All the endpoints for the service of the IAdd type:
Endpoint - address:  http://localhost:8000/samples/service
           binding name:  WSHttpBinding
           contract name: IAdd

Endpoint - address:  net.tcp://localhost:9000/samples/service
           binding name:  NetTcpBinding
           contract name: IAdd

All endpoints for the service with the contract QName
         http://Microsoft.ServiceModel.Samples.IAdd
Endpoint - address:  http://localhost:8000/samples/service
           binding name:  WSHttpBinding
           contract name: IAdd
           contract namespace: http://Microsoft.ServiceModel.Samples

Endpoint - address:  net.tcp://localhost:9000/samples/service
           binding name:  NetTcpBinding
           contract name: IAdd
           contract namespace: http://Microsoft.ServiceModel.Samples

The service is ready.
Press <ENTER> to terminate service.
*/

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft