ServiceEndpointCollection Class
A collection that contains the endpoints for a service.
System.Collections.ObjectModel::Collection<ServiceEndpoint>
System.ServiceModel.Description::ServiceEndpointCollection
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The ServiceEndpointCollection type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of elements actually contained in the Collection<T>. (Inherited from Collection<T>.) |
![]() | Item | Gets or sets the element at the specified index. (Inherited from Collection<T>.) |
![]() | Items | Gets a IList<T> wrapper around the Collection<T>. (Inherited from Collection<T>.) |
| Name | Description | |
|---|---|---|
![]() | Add | Adds an object to the end of the Collection<T>. (Inherited from Collection<T>.) |
![]() | Clear | Removes all elements from the Collection<T>. (Inherited from Collection<T>.) |
![]() | ClearItems | Removes all elements from the Collection<T>. (Inherited from Collection<T>.) |
![]() | Contains | Determines whether an element is in the Collection<T>. (Inherited from Collection<T>.) |
![]() | CopyTo | 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) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | Find(Type) | Returns the first service endpoint found that satisfies the specified contract type from the collection of service endpoints. |
![]() | Find(Uri) | Returns a service endpoint with a specified address from the collection of service endpoints. |
![]() | Find(XmlQualifiedName) | Returns a service endpoint with a specified namespace and contract name from the collection of service endpoints. |
![]() | 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(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) | Returns a collection of all the service endpoints for a specified type of service. |
![]() | FindAll(XmlQualifiedName) | Returns a collection of all the service endpoints for a specified service name. |
![]() | GetEnumerator | Returns an enumerator that iterates through the Collection<T>. (Inherited from Collection<T>.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IndexOf | 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 | Inserts an element into the Collection<T> at the specified index. (Inherited from Collection<T>.) |
![]() | InsertItem | Inserts an item into the collection at the specified index. (Overrides Collection<T>::InsertItem(Int32, T).) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Remove | Removes the first occurrence of a specific object from the Collection<T>. (Inherited from Collection<T>.) |
![]() | RemoveAt | Removes the element at the specified index of the Collection<T>. (Inherited from Collection<T>.) |
![]() | RemoveItem | Removes the element at the specified index of the Collection<T>. (Inherited from Collection<T>.) |
![]() | SetItem | Replaces the element in the collection at the specified index. (Overrides Collection<T>::SetItem(Int32, T).) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | ICollection::CopyTo | Copies the elements of the ICollection to an Array, starting at a particular Array index. (Inherited from Collection<T>.) |
![]() ![]() | ICollection<T>::IsReadOnly | Gets a value indicating whether the ICollection<T> is read-only. (Inherited from Collection<T>.) |
![]() ![]() | ICollection::IsSynchronized | Gets a value indicating whether access to the ICollection is synchronized (thread safe). (Inherited from Collection<T>.) |
![]() ![]() | ICollection::SyncRoot | Gets an object that can be used to synchronize access to the ICollection. (Inherited from Collection<T>.) |
![]() ![]() | IEnumerable::GetEnumerator | Returns an enumerator that iterates through a collection. (Inherited from Collection<T>.) |
![]() ![]() | IList::Add | Adds an item to the IList. (Inherited from Collection<T>.) |
![]() ![]() | IList::Contains | Determines whether the IList contains a specific value. (Inherited from Collection<T>.) |
![]() ![]() | IList::IndexOf | Determines the index of a specific item in the IList. (Inherited from Collection<T>.) |
![]() ![]() | IList::Insert | Inserts an item into the IList at the specified index. (Inherited from Collection<T>.) |
![]() ![]() | IList::IsFixedSize | Gets a value indicating whether the IList has a fixed size. (Inherited from Collection<T>.) |
![]() ![]() | IList::IsReadOnly | Gets a value indicating whether the IList is read-only. (Inherited from Collection<T>.) |
![]() ![]() | IList::Item | Gets or sets the element at the specified index. (Inherited from Collection<T>.) |
![]() ![]() | IList::Remove | Removes the first occurrence of a specific object from the IList. (Inherited from Collection<T>.) |
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. */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

