ServiceEndpointCollection ServiceEndpointCollection ServiceEndpointCollection ServiceEndpointCollection Class

Definition

A collection that contains the endpoints for a service.

public ref class ServiceEndpointCollection : System::Collections::ObjectModel::Collection<System::ServiceModel::Description::ServiceEndpoint ^>
public class ServiceEndpointCollection : System.Collections.ObjectModel.Collection<System.ServiceModel.Description.ServiceEndpoint>
type ServiceEndpointCollection = class
    inherit Collection<ServiceEndpoint>
Public Class ServiceEndpointCollection
Inherits Collection(Of ServiceEndpoint)
Inheritance
ServiceEndpointCollectionServiceEndpointCollectionServiceEndpointCollectionServiceEndpointCollection

Examples

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.
*/

Remarks

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.

Methods

Add(T) Add(T) Add(T) Add(T)

Adds an object to the end of the Collection<T>.

(Inherited from Collection<T>)
Clear() Clear() Clear() Clear()

Removes all elements from the Collection<T>.

(Inherited from Collection<T>)
ClearItems() ClearItems() ClearItems() ClearItems()

Removes all elements from the Collection<T>.

(Inherited from Collection<T>)
Contains(T) Contains(T) Contains(T) Contains(T)

Determines whether an element is in the Collection<T>.

(Inherited from Collection<T>)
CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32) CopyTo(T[], Int32)

Copies the entire Collection<T> to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from Collection<T>)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Find(Type) Find(Type) Find(Type) Find(Type)

Returns the first service endpoint found that satisfies the specified contract type from the collection of service endpoints.

Find(Type, XmlQualifiedName) Find(Type, XmlQualifiedName) Find(Type, XmlQualifiedName) Find(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.

Find(Uri) Find(Uri) Find(Uri) Find(Uri)

Returns a service endpoint with a specified address from the collection of service endpoints.

Find(XmlQualifiedName) Find(XmlQualifiedName) Find(XmlQualifiedName) Find(XmlQualifiedName)

Returns a service endpoint with a specified namespace and contract name from the collection of service endpoints.

Find(XmlQualifiedName, XmlQualifiedName) Find(XmlQualifiedName, XmlQualifiedName) Find(XmlQualifiedName, XmlQualifiedName) Find(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.

FindAll(Type) FindAll(Type) FindAll(Type) FindAll(Type)

Returns a collection of all the service endpoints for a specified type of service.

FindAll(XmlQualifiedName) FindAll(XmlQualifiedName) FindAll(XmlQualifiedName) FindAll(XmlQualifiedName)

Returns a collection of all the service endpoints for a specified service name.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the Collection<T>.

(Inherited from Collection<T>)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(T) IndexOf(T) IndexOf(T) IndexOf(T)

Searches for the specified object and returns the zero-based index of the first occurrence within the entire Collection<T>.

(Inherited from Collection<T>)
Insert(Int32, T) Insert(Int32, T) Insert(Int32, T) Insert(Int32, T)

Inserts an element into the Collection<T> at the specified index.

(Inherited from Collection<T>)
InsertItem(Int32, ServiceEndpoint) InsertItem(Int32, ServiceEndpoint) InsertItem(Int32, ServiceEndpoint) InsertItem(Int32, ServiceEndpoint)

Inserts an item into the collection at the specified index.

InsertItem(Int32, T) InsertItem(Int32, T) InsertItem(Int32, T) InsertItem(Int32, T)

Inserts an element into the Collection<T> at the specified index.

(Inherited from Collection<T>)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(T) Remove(T) Remove(T) Remove(T)

Removes the first occurrence of a specific object from the Collection<T>.

(Inherited from Collection<T>)
RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes the element at the specified index of the Collection<T>.

(Inherited from Collection<T>)
RemoveItem(Int32) RemoveItem(Int32) RemoveItem(Int32) RemoveItem(Int32)

Removes the element at the specified index of the Collection<T>.

(Inherited from Collection<T>)
SetItem(Int32, ServiceEndpoint) SetItem(Int32, ServiceEndpoint) SetItem(Int32, ServiceEndpoint) SetItem(Int32, ServiceEndpoint)

Replaces the element in the collection at the specified index.

SetItem(Int32, T) SetItem(Int32, T) SetItem(Int32, T) SetItem(Int32, T)

Replaces the element at the specified index.

(Inherited from Collection<T>)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Properties

Count Count Count Count

Gets the number of elements actually contained in the Collection<T>.

(Inherited from Collection<T>)
ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

(Inherited from Collection<T>)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

(Inherited from Collection<T>)
ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly ICollection<T>.IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

(Inherited from Collection<T>)
IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

Gets a value indicating whether the IList has a fixed size.

(Inherited from Collection<T>)
IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

Gets a value indicating whether the IList is read-only.

(Inherited from Collection<T>)
IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

Gets or sets the element at the specified index.

(Inherited from Collection<T>)
Items Items Items Items

Gets a IList<T> wrapper around the Collection<T>.

(Inherited from Collection<T>)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the element at the specified index.

(Inherited from Collection<T>)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

(Inherited from Collection<T>)
IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

(Inherited from Collection<T>)
IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

Adds an item to the IList.

(Inherited from Collection<T>)
IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

Determines whether the IList contains a specific value.

(Inherited from Collection<T>)
IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

Determines the index of a specific item in the IList.

(Inherited from Collection<T>)
IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

Inserts an item into the IList at the specified index.

(Inherited from Collection<T>)
IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

Removes the first occurrence of a specific object from the IList.

(Inherited from Collection<T>)

Extension Methods

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

Returns a filtered collection of the child elements of every element and document in the source collection. Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

Removes every node in the source collection from its parent node.

Applies to

See also