EndpointAddress EndpointAddress EndpointAddress EndpointAddress Class

定义

提供客户端用来与服务终结点进行通信的唯一网络地址。Provides a unique network address that a client uses to communicate with a service endpoint.

public ref class EndpointAddress
public class EndpointAddress
type EndpointAddress = class
Public Class EndpointAddress
继承
EndpointAddressEndpointAddressEndpointAddressEndpointAddress

示例

using System;
using System.Configuration;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

using System.Text;

namespace Microsoft.WCF.Documentation
{
  class HostApplication
  {

    static void Main()
    {
      HostApplication app = new HostApplication();
      app.Run();
    }

    private void Run()
    {

            // Get base address from app settings in configuration
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

            //Create new address headers for special services and add them to an array
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader(
                "specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader(
                "specialservice2", "http://localhost:8000/service", 2);

            // Enumerate address headers and their properties from the array.
            AddressHeader[] addressHeaders = new AddressHeader[2] { addressHeader1, addressHeader2 };
            foreach (AddressHeader addressHeader in addressHeaders)
            {
                Console.WriteLine("AddressHeader - namespace:\t\t{0}", addressHeader.Namespace);
                Console.WriteLine("              - name:\t\t\t{0}", addressHeader.Name);
                Console.WriteLine("              - value:\t\t\t{0}", addressHeader.GetValue<int>());
                Console.WriteLine("              - type:\t\t\t{0}", addressHeader.GetType());
                Console.WriteLine("              - hashcode:\t\t{0}", addressHeader.GetHashCode());
                Console.WriteLine("              - equals addressHeader1:\t{0}", addressHeader.Equals(addressHeader1));
             //   Console.WriteLine("              - Is SOAP1.1 supported:\t{0}", addressHeader.ToMessageHeader().IsMessageVersionSupported(MessageVersion.WSAddressingSoap10));
                Console.WriteLine();
            }
            Console.WriteLine();

            //Add the array of address headers to an endpoint address
            EndpointAddress endpointAddress = new EndpointAddress(
                        new Uri("http://localhost:8003/servicemodelsamples/service"), addressHeaders);

            //Create a "special" service endpoint that uses the endpointAddress.
            string WSHttpBindingName = "Binding1";
            ServiceEndpoint specialServiceEndpoint = new ServiceEndpoint(
                ContractDescription.GetContract(typeof(CalculatorService)), new WSHttpBinding(WSHttpBindingName), endpointAddress
                );

            // Create a ServiceHost for the CalculatorService type that uses the base address.
            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            //Add the specialServiceEndpoint to the serviceHost.
            serviceHost.Description.Endpoints.Add(specialServiceEndpoint);

            // Enumerate the service endpoints and some of their properties from the serviceHost.
            Console.WriteLine("Service endpoints:");
            ServiceDescription desc = serviceHost.Description;
            foreach (ServiceEndpoint endpoint in desc.Endpoints)
            {
                Console.WriteLine("Endpoint - address:  {0}", endpoint.Address);
                Console.WriteLine("         - binding name:\t\t{0}", endpoint.Binding.Name);
                // Console.WriteLine("         - binding name:\t\t{0}", endpoint.);
                Console.WriteLine("         - contract name:\t\t{0}", endpoint.Contract.Name);
                Console.WriteLine("         - contains addressHeader1:\t{0}", endpoint.Address.Headers.Contains(addressHeader1));
                Console.WriteLine("         - count of address headers:\t{0}", endpoint.Address.Headers.Count);
                Console.WriteLine();
            }

            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.WriteLine();
            Console.ReadLine();

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

        }
    }
  }

注解

终结点地址唯一标识服务的终结点。An endpoint address uniquely identifies the endpoint for a service.

终结点地址属于服务终结点。服务终结点还包含终结点的绑定、协定和行为。The endpoint address belongs to the service endpoint, which also contains the binding, contract and behaviors for the endpoint.

EndpointAddress 包含一个 URI,以及包括标识、WSDL 元素和可选标头集合在内的地址属性。The EndpointAddress contains a URI and address properties that include an identity, WSDL elements, and a collection of optional headers. 可选标头用于提供其他更多详细寻址信息来标识终结点或与终结点交互。The optional headers are used to provide additional, more detailed addressing information to identify or interact with the endpoint. 例如,它们可用于指示当有多个实例可用时,要使用哪个服务实例来处理从特定用户传入的消息。For example, they can be used to indicate which instance of a service is to be used to process an incoming message from a particular user when multiple instances are available.

您可以通过使用代码以强制方式或通过配置以声明方式指定服务的终结点地址。The endpoint address for a service can be specified either imperatively using code or declaratively through configuration. 在代码中定义终结点通常是不可行的,因为已部署服务的绑定和地址通常与在部署服务时所用的绑定和地址不同。Defining endpoints in code is usually not practical because the bindings and addresses for a deployed service are typically different from those used while the service is being developed. 它是定义使用配置的服务终结点更为可行。It is more practical to define service endpoints using configuration.

EndpointAddress 不实现 ISerializable 接口,因此不可序列化。EndpointAddress does not implement the ISerializable interface and so is not serializable. 若要使终结点作为服务协定的一部分进行公开,它必须是可序列化的,而且还必须与 Web 服务寻址 (WS-Addressing) 协议兼容。For an endpoint to be exposed as part of a service contract it must be serializable and it must also be compliant with the Web Service Addressing (WS-Addressing) protocol. 与 WS-Addressing 1.0 版和 2004 年 8 月版兼容的可序列化终结点分别由 EndpointAddress10EndpointAddressAugust2004 类提供。Serializable endpoints that are compliant with version 1.0 and the August 2004 version of WS-Addressing are provided, respectively, by the EndpointAddress10 and EndpointAddressAugust2004 classes.

构造函数

EndpointAddress(String) EndpointAddress(String) EndpointAddress(String) EndpointAddress(String)

使用指定的 URI 字符串初始化 EndpointAddress 类的新实例。Initializes a new instance of the EndpointAddress class with a specified URI string.

EndpointAddress(Uri, AddressHeader[]) EndpointAddress(Uri, AddressHeader[]) EndpointAddress(Uri, AddressHeader[]) EndpointAddress(Uri, AddressHeader[])

使用指定的 URI 和标头初始化 EndpointAddress 类的新实例。Initializes a new instance of the EndpointAddress class with a specified URI and headers.

EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection)

使用指定的 URI、标识和标头集合初始化 EndpointAddress 类的新实例。Initializes a new instance of the EndpointAddress class with a specified URI, identity, and header collection.

EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection, XmlDictionaryReader, XmlDictionaryReader) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection, XmlDictionaryReader, XmlDictionaryReader) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection, XmlDictionaryReader, XmlDictionaryReader) EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection, XmlDictionaryReader, XmlDictionaryReader)

使用指定的 URI、标识、标头集合、元数据和扩展读取器初始化 EndpointAddress 类的新实例。Initializes a new instance of the EndpointAddress class with a specified URI, identity, header collection, and metadata and extension readers.

EndpointAddress(Uri, EndpointIdentity, AddressHeader[]) EndpointAddress(Uri, EndpointIdentity, AddressHeader[]) EndpointAddress(Uri, EndpointIdentity, AddressHeader[]) EndpointAddress(Uri, EndpointIdentity, AddressHeader[])

使用指定的 URI、标识和标头初始化 EndpointAddress 类的新实例。Initializes a new instance of the EndpointAddress class with a specified URI, identity, and headers.

属性

AnonymousUri AnonymousUri AnonymousUri AnonymousUri

获取匿名 URI 的与版本无关的表示形式。Gets a version-neutral representation of the anonymous URI.

Headers Headers Headers Headers

获取生成器可以创建的终结点的地址标头的集合。Gets the collection of address headers for the endpoints that the builder can create.

Identity Identity Identity Identity

获取用于验证终结点的标识。Gets the identity for the endpoint used to authenticate it.

IsAnonymous IsAnonymous IsAnonymous IsAnonymous

获取一个值,该值指示终结点是否为匿名。Gets a value that indicates whether the endpoint is anonymous.

IsNone IsNone IsNone IsNone

获取一个值,该值指示终结点 URI 是否为 NoneUriGets a value that indicates whether the URI for the endpoint is the NoneUri.

NoneUri NoneUri NoneUri NoneUri

获取一个与版本无关的 URI,用作不得向其发送消息的终结点的地址。Gets a version-neutral URI used for the address of an endpoint to which a message must not be sent.

Uri Uri Uri Uri

获取终结点的 URI。Gets the URI for the endpoint.

方法

ApplyTo(Message) ApplyTo(Message) ApplyTo(Message) ApplyTo(Message)

将终结点地址的 URI 和属性分配给指定消息的标头值。Assigns the URI and properties of the endpoint address to the values of the headers of a specified message.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示指定的对象与当前终结点地址是否等同。Returns a value that indicates whether a specified object is equivalent to the current endpoint address.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

提供当前终结点地址的唯一哈希代码。Provides a unique hash code for the current endpoint address.

GetReaderAtExtensions() GetReaderAtExtensions() GetReaderAtExtensions() GetReaderAtExtensions()

获取使您可以访问扩展的 XML 字典读取器。Gets the XML dictionary reader that provides access to the extensions.

GetReaderAtMetadata() GetReaderAtMetadata() GetReaderAtMetadata() GetReaderAtMetadata()

获取使您可以访问终结点元数据的 XML 字典读取器。Gets the XML dictionary reader that provides access to the metadata for an endpoint.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ReadFrom(AddressingVersion, XmlDictionaryReader) ReadFrom(AddressingVersion, XmlDictionaryReader) ReadFrom(AddressingVersion, XmlDictionaryReader) ReadFrom(AddressingVersion, XmlDictionaryReader)

从指定的 XML 读取器读取指定地址版本的终结点地址。Reads an endpoint address for a specified address version from a specified XML dictionary reader.

ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

从指定的 XML 字典读取器读取具有指定限定名的指定地址版本的终结点地址。Reads an endpoint address for a specified address version with a specified qualified name from a specified XML dictionary reader.

ReadFrom(AddressingVersion, XmlReader) ReadFrom(AddressingVersion, XmlReader) ReadFrom(AddressingVersion, XmlReader) ReadFrom(AddressingVersion, XmlReader)

从指定的 XML 读取器读取指定地址版本的终结点地址。Reads an endpoint address for a specified address version from a specified XML reader.

ReadFrom(AddressingVersion, XmlReader, String, String) ReadFrom(AddressingVersion, XmlReader, String, String) ReadFrom(AddressingVersion, XmlReader, String, String) ReadFrom(AddressingVersion, XmlReader, String, String)

从指定的 XML 读取器读取具有指定限定名的指定地址版本的终结点地址。Reads an endpoint address for a specified address version with a specified qualified name from a specified XML reader.

ReadFrom(XmlDictionaryReader) ReadFrom(XmlDictionaryReader) ReadFrom(XmlDictionaryReader) ReadFrom(XmlDictionaryReader)

从指定的 XML 读取器读取终结点地址。Reads an endpoint address from a specified XML dictionary reader.

ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString) ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

从指定的 XML 读取器读取具有指定限定名的终结点地址。Reads an endpoint address with a specified qualified name from a specified XML dictionary reader.

ToString() ToString() ToString() ToString()

返回终结点地址中包含的 URI 的规范字符串表示形式。Returns a canonical string representation of the URI that is contained in the endpoint address.

WriteContentsTo(AddressingVersion, XmlDictionaryWriter) WriteContentsTo(AddressingVersion, XmlDictionaryWriter) WriteContentsTo(AddressingVersion, XmlDictionaryWriter) WriteContentsTo(AddressingVersion, XmlDictionaryWriter)

将节点的所有子节点保存到指定的 XML 字典编写器中。Saves all the child nodes of the node to the XML dictionary writer specified.

WriteContentsTo(AddressingVersion, XmlWriter) WriteContentsTo(AddressingVersion, XmlWriter) WriteContentsTo(AddressingVersion, XmlWriter) WriteContentsTo(AddressingVersion, XmlWriter)

将节点的所有子节点保存到指定的 XML 编写器中。Saves all the child nodes of the node to the XML writer specified.

WriteTo(AddressingVersion, XmlDictionaryWriter) WriteTo(AddressingVersion, XmlDictionaryWriter) WriteTo(AddressingVersion, XmlDictionaryWriter) WriteTo(AddressingVersion, XmlDictionaryWriter)

将指定版本的当前终结点地址保存到指定的 XML 字典编写器。Saves the current endpoint address of a specified version to a specified XML dictionary writer.

WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString) WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString) WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString) WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString)

使用指定的命名空间和本地名称将指定版本的当前终结点地址保存到 XML 字典编写器。Saves the current endpoint address of a specified version to an XML dictionary writer with a specified namespace and local name.

WriteTo(AddressingVersion, XmlWriter) WriteTo(AddressingVersion, XmlWriter) WriteTo(AddressingVersion, XmlWriter) WriteTo(AddressingVersion, XmlWriter)

将指定版本的当前终结点地址保存到指定的 XML 编写器。Saves the current endpoint address of a specified version to a specified XML writer.

WriteTo(AddressingVersion, XmlWriter, String, String) WriteTo(AddressingVersion, XmlWriter, String, String) WriteTo(AddressingVersion, XmlWriter, String, String) WriteTo(AddressingVersion, XmlWriter, String, String)

使用指定的命名空间和本地名称将指定版本的当前终结点地址保存到 XML 编写器。Saves the current endpoint address of a specified version to an XML writer with a specified namespace and local name.

操作员

Equality(EndpointAddress, EndpointAddress) Equality(EndpointAddress, EndpointAddress) Equality(EndpointAddress, EndpointAddress) Equality(EndpointAddress, EndpointAddress)

返回一个值,该值指示指定的终结点地址是否不等同。Returns a value that indicates whether specified endpoint addresses are not equivalent.

Inequality(EndpointAddress, EndpointAddress) Inequality(EndpointAddress, EndpointAddress) Inequality(EndpointAddress, EndpointAddress) Inequality(EndpointAddress, EndpointAddress)

返回一个值,该值指示指定的终结点地址是否不等同。Returns a value that indicates whether specified endpoint addresses are not equivalent.

适用于