EndpointAddress 类

定义

提供客户端用来与服务终结点通信的唯一网络地址。

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

示例

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();
        }
    }
  }

注解

终结点地址唯一标识服务的终结点。

终结点地址属于服务终结点,该终结点还包含终结点的绑定、协定和行为。

包含 EndpointAddress URI 和地址属性,其中包括标识、WSDL 元素和可选标头集合。 可选标头用于提供其他更详细的寻址信息,以标识或与终结点交互。 例如,它们可用于指示当多个实例可用时,服务实例将用于处理来自特定用户的传入消息。

可以使用代码以命令方式指定服务的终结点地址,或者通过配置以声明式方式指定。 在代码中定义终结点通常不可行,因为部署服务的绑定和地址通常不同于在开发服务时使用的终结点。 使用配置定义服务终结点更为实用。

EndpointAddress 不实现 ISerializable 接口,因此不可序列化。 要使终结点作为服务协定的一部分公开,它必须可序列化,并且还必须符合 Web 服务寻址(WS-Addressing)协议。 WS-Addressing 版本和类分别EndpointAddress10EndpointAddressAugust2004提供符合版本 1.0 和 2004 年 8 月版本的可序列化终结点。

构造函数

名称 说明
EndpointAddress(String)

使用指定的 URI 字符串初始化类的新实例 EndpointAddress

EndpointAddress(Uri, AddressHeader[])

使用指定的 URI 和标头初始化类的新实例 EndpointAddress

EndpointAddress(Uri, EndpointIdentity, AddressHeader[])

使用指定的 URI、标识和标头初始化类的新实例 EndpointAddress

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

使用指定的 URI、标识、标头集合和元数据和扩展读取器初始化类的新实例 EndpointAddress

EndpointAddress(Uri, EndpointIdentity, AddressHeaderCollection)

使用指定的 URI、标识和标头集合初始化类的新实例 EndpointAddress

属性

名称 说明
AnonymousUri

获取匿名 URI 的版本中性表示形式。

Headers

获取生成器可以创建的终结点的地址标头的集合。

Identity

获取用于对其进行身份验证的终结点的标识。

IsAnonymous

获取一个值,该值指示终结点是否为 匿名终结点。

IsNone

获取一个值,该值指示终结点的 URI 是否为 NoneUri.

NoneUri

获取一个版本中性 URI,该 URI 用于消息不得发送到的终结点的地址。

Uri

获取终结点的 URI。

方法

名称 说明
ApplyTo(Message)

将终结点地址的 URI 和属性分配给指定消息的标头的值。

Equals(Object)

返回一个值,该值指示指定的对象是否等效于当前终结点地址。

GetHashCode()

为当前终结点地址提供唯一的哈希代码。

GetReaderAtExtensions()

获取提供对扩展的访问权限的 XML 字典读取器。

GetReaderAtMetadata()

获取提供对终结点元数据的访问权限的 XML 字典读取器。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ReadFrom(AddressingVersion, XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

从指定的 XML 字典读取器中读取具有指定限定名称的指定地址版本的终结点地址。

ReadFrom(AddressingVersion, XmlDictionaryReader)

从指定的 XML 字典读取器读取指定地址版本的终结点地址。

ReadFrom(AddressingVersion, XmlReader, String, String)

从指定的 XML 读取器中读取具有指定限定名称的指定地址版本的终结点地址。

ReadFrom(AddressingVersion, XmlReader)

从指定的 XML 读取器读取指定地址版本的终结点地址。

ReadFrom(XmlDictionaryReader, XmlDictionaryString, XmlDictionaryString)

从指定的 XML 字典读取器中读取具有指定限定名称的终结点地址。

ReadFrom(XmlDictionaryReader)

从指定的 XML 字典读取器读取终结点地址。

ToString()

返回终结点地址中包含的 URI 的规范字符串表示形式。

WriteContentsTo(AddressingVersion, XmlDictionaryWriter)

将节点的所有子节点保存到指定的 XML 字典编写器。

WriteContentsTo(AddressingVersion, XmlWriter)

将节点的所有子节点保存到指定的 XML 编写器。

WriteTo(AddressingVersion, XmlDictionaryWriter, XmlDictionaryString, XmlDictionaryString)

将指定版本的当前终结点地址保存到具有指定命名空间和本地名称的 XML 字典编写器。

WriteTo(AddressingVersion, XmlDictionaryWriter)

将指定版本的当前终结点地址保存到指定的 XML 字典编写器。

WriteTo(AddressingVersion, XmlWriter, String, String)

将指定版本的当前终结点地址保存到具有指定命名空间和本地名称的 XML 编写器。

WriteTo(AddressingVersion, XmlWriter)

将指定版本的当前终结点地址保存到指定的 XML 编写器。

运营商

名称 说明
Equality(EndpointAddress, EndpointAddress)

返回一个值,该值指示指定的终结点地址是否不等效。

Inequality(EndpointAddress, EndpointAddress)

返回一个值,该值指示指定的终结点地址是否不等效。

适用于