ServiceEndpointCollection クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
サービスのエンドポイントを含むコレクション。
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)
- 継承
例
Find メソッドと FindAll メソッドを使用して、さまざまな検索基準を満たす ServiceEndpoint オブジェクトを列挙する方法を次の例に示します。
[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.
*/
注釈
サービスのエンドポイントのコレクションは、複数のエンドポイントを持つサービスを管理するためにメタデータ API によって使用されます。 ServiceEndpointCollection は、たとえば、WSDL ポートの種類からサービス エンドポイントを作成するときに、Endpoints プロパティと ImportAllEndpoints メソッドによって返されます。
このコレクションは、特定の名前またはアドレスを持つ特定の種類のエンドポイントを返す Find を実行したり、指定したコントラクト型または名前の基準を満たすエンドポイントをすべて返す FindAll を実行したりするための機能を提供します。
プロパティ
Count |
Collection<T> に実際に含まれる要素の数を取得します。 (継承元 Collection<T>) |
Item[Int32] |
指定したインデックスにある要素を取得または設定します。 (継承元 Collection<T>) |
Items |
IList<T> をラップする Collection<T> ラッパーを取得します。 (継承元 Collection<T>) |
メソッド
Add(T) |
Collection<T> の末尾にオブジェクトを追加します。 (継承元 Collection<T>) |
Clear() |
Collection<T> からすべての要素を削除します。 (継承元 Collection<T>) |
ClearItems() |
Collection<T> からすべての要素を削除します。 (継承元 Collection<T>) |
Contains(T) |
ある要素が Collection<T> 内に存在するかどうかを判断します。 (継承元 Collection<T>) |
CopyTo(T[], Int32) |
Collection<T> 全体を互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。 (継承元 Collection<T>) |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Find(Type) |
サービス エンドポイントのコレクションから、指定したコントラクト型に一致する最初のサービス エンドポイントを検索して返します。 |
Find(Type, XmlQualifiedName) |
サービス エンドポイントのコレクションから、指定したコントラクト型の、指定したバインディング名と名前空間を持つサービス エンドポイントを返します。 |
Find(Uri) |
サービス エンドポイントのコレクションから、指定したアドレスを持つサービス エンドポイントを返します。 |
Find(XmlQualifiedName) |
サービス エンドポイントのコレクションから、指定した名前空間とコントラクト名を持つサービス エンドポイントを返します。 |
Find(XmlQualifiedName, XmlQualifiedName) |
サービス エンドポイントのコレクションから、指定したコントラクト名と名前空間、および指定したバインディング名と名前空間を持つ最初のサービス エンドポイントを返します。 |
FindAll(Type) |
指定したサービス型のすべてのサービス エンドポイントのコレクションを返します。 |
FindAll(XmlQualifiedName) |
指定したサービス名のすべてのサービス エンドポイントのコレクションを返します。 |
GetEnumerator() |
Collection<T> を反復処理する列挙子を返します。 (継承元 Collection<T>) |
GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
IndexOf(T) |
Collection<T> 全体から指定したオブジェクトを検索し、最初に見つかったオブジェクトのインデックス (0 から始まる) を返します。 (継承元 Collection<T>) |
Insert(Int32, T) |
Collection<T> 内の指定したインデックスの位置に要素を挿入します。 (継承元 Collection<T>) |
InsertItem(Int32, ServiceEndpoint) |
コレクション内の指定したインデックスの位置に項目を挿入します。 |
InsertItem(Int32, T) |
Collection<T> 内の指定したインデックスの位置に要素を挿入します。 (継承元 Collection<T>) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
Remove(T) |
特定のオブジェクトが Collection<T> 内にあるときに、最初に出現したものを削除します。 (継承元 Collection<T>) |
RemoveAt(Int32) |
Collection<T> の指定したインデックスにある要素を削除します。 (継承元 Collection<T>) |
RemoveItem(Int32) |
Collection<T> の指定したインデックスにある要素を削除します。 (継承元 Collection<T>) |
SetItem(Int32, ServiceEndpoint) |
コレクション内の指定したインデックス位置にある要素を置き換えます。 |
SetItem(Int32, T) |
指定したインデックス位置にある要素を置き換えます。 (継承元 Collection<T>) |
ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |