WSHttpBindingBase 类

定义

提供一个基类,该基类具有 WSHttpBindingWSFederationHttpBinding 共有的成员。

public ref class WSHttpBindingBase abstract : System::ServiceModel::Channels::Binding
public ref class WSHttpBindingBase abstract : System::ServiceModel::Channels::Binding, System::ServiceModel::Channels::IBindingRuntimePreferences
public abstract class WSHttpBindingBase : System.ServiceModel.Channels.Binding
public abstract class WSHttpBindingBase : System.ServiceModel.Channels.Binding, System.ServiceModel.Channels.IBindingRuntimePreferences
type WSHttpBindingBase = class
    inherit Binding
type WSHttpBindingBase = class
    inherit Binding
    interface IBindingRuntimePreferences
Public MustInherit Class WSHttpBindingBase
Inherits Binding
Public MustInherit Class WSHttpBindingBase
Inherits Binding
Implements IBindingRuntimePreferences
继承
WSHttpBindingBase
派生
实现

示例

下面的示例演示如何使用 WSHttpBindingBase 类与派生类、WSHttpBinding 以及 WSFederationHttpBinding 所提供的功能。


// Define a service contract for the calculator.
[ServiceContract()]
public interface ICalculator
{
    [OperationContract(IsOneWay = false)]
    double Add(double n1, double n2);
    [OperationContract(IsOneWay = false)]
    double Subtract(double n1, double n2);
    [OperationContract(IsOneWay = false)]
    double Multiply(double n1, double n2);
    [OperationContract(IsOneWay = false)]
    double Divide(double n1, double n2);
}

// Service class which implements the service contract.
public class CalculatorService : ICalculator
{
    public double Add(double n1, double n2)
    {
        double result = n1 + n2;
        return result;
    }

    public double Subtract(double n1, double n2)
    {
        double result = n1 - n2;
        return result;
    }

    public double Multiply(double n1, double n2)
    {
        double result = n1 * n2;
        return result;
    }

    public double Divide(double n1, double n2)
    {
        double result = n1 / n2;
        return result;
    }

    // Create and configure bindings within this EXE console application.
    public static void Main()
    {
        // Create a WSHttpBinding
        WSHttpBinding binding1 = new WSHttpBinding();

    binding1.BypassProxyOnLocal =  true;

    EnvelopeVersion envelopeVersion =
    binding1.EnvelopeVersion;

    HostNameComparisonMode hostnameComparisonMode =
    binding1.HostNameComparisonMode;

    long maxBufferPoolSize =
        binding1.MaxBufferPoolSize;

    long maxReceivedMessageSize =
    binding1.MaxReceivedMessageSize;

    WSMessageEncoding messageEncoding =
    binding1.MessageEncoding;

    Uri proxyAddress =
        binding1.ProxyAddress;

    XmlDictionaryReaderQuotas readerQuotas =
    binding1.ReaderQuotas;

    OptionalReliableSession reliableSession =
    binding1.ReliableSession;

    string scheme = binding1.Scheme;

    Encoding textEncoding =
        binding1.TextEncoding;

    bool transactionFlow =
        binding1.TransactionFlow;

    bool useDefaultWebProxy =
        binding1.UseDefaultWebProxy;

    BindingElementCollection bindingElements =
            binding1.CreateBindingElements();

        // Set WSHttpBinding binding property values
        binding1.Name = "Binding1";
        binding1.HostNameComparisonMode =
           HostNameComparisonMode.StrongWildcard;
        binding1.Security.Mode = SecurityMode.Message;
        binding1.ReliableSession.Enabled = false;
        binding1.TransactionFlow = false;
       // binding1.Security.Message.DefaultProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

        // Enumerate properties of the binding1.
        Console.WriteLine("WSHttpBinding binding1 properties:");
        Console.WriteLine("      - name:\t\t\t{0}", binding1.Name);
        Console.WriteLine("      - hostname comparison:\t{0}", binding1.HostNameComparisonMode);
        Console.WriteLine("      - security mode:\t\t{0}", binding1.Security.Mode);
        Console.WriteLine("      - RM enabled:\t\t{0}", binding1.ReliableSession.Enabled);
        Console.WriteLine("      - transaction flow:\t{0}", binding1.TransactionFlow);
        //Console.WriteLine("      - message security:\t{0}", binding1.Security.Message.DefaultProtectionLevel);
        Console.WriteLine("      - transport scheme:\t{0}", binding1.Scheme);
        Console.WriteLine("      - max message size:\t{0}", binding1.MaxReceivedMessageSize);
        Console.WriteLine("      - default text encoding:\t{0}", binding1.TextEncoding);
        Console.WriteLine();

        // Create a WSFederationBinding with a message security mode
        // and with a reliable session enabled.
        WSFederationHttpBinding binding3 = new WSFederationHttpBinding(WSFederationHttpSecurityMode.Message, true);

        // Enumerate properties of the binding2.
        Console.WriteLine("WSFederationBinding binding3 properties:");
        Console.WriteLine("      - security mode:\t\t{0}", binding3.Security.Mode);
        Console.WriteLine("      - RM enabled:\t\t{0}", binding3.ReliableSession.Enabled);
        Console.WriteLine();
        Console.WriteLine("Press <ENTER> to terminate.");
        Console.ReadLine();
    }

static void SnippetReceiveSynchronously ()
{
    WSHttpBinding binding = new WSHttpBinding();
    IBindingRuntimePreferences s  =
                       binding.GetProperty<IBindingRuntimePreferences>
                       (new BindingParameterCollection());
    bool receiveSynchronously = s.ReceiveSynchronously;
}
}

' Define a service contract for the calculator.
<ServiceContract()> _
Public Interface ICalculator
    <OperationContract(IsOneWay := False)> _
    Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double
    <OperationContract(IsOneWay := False)> _
    Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double
    <OperationContract(IsOneWay := False)> _
    Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double
    <OperationContract(IsOneWay := False)> _
    Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double
End Interface

' Service class which implements the service contract.
Public Class CalculatorService
    Implements ICalculator
    Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Add
        Dim result = n1 + n2
        Return result
    End Function

    Public Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Subtract
        Dim result = n1 - n2
        Return result
    End Function

    Public Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Multiply
        Dim result = n1 * n2
        Return result
    End Function

    Public Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Divide
        Dim result = n1 / n2
        Return result
    End Function

    ' Create and configure bindings within this EXE console application.
    Public Shared Sub Main()
        ' Create a WSHttpBinding
        Dim binding1 As New WSHttpBinding()

    binding1.BypassProxyOnLocal = True

    Dim envelopeVersion As EnvelopeVersion = binding1.EnvelopeVersion

    Dim hostnameComparisonMode As HostNameComparisonMode = binding1.HostNameComparisonMode

        Dim maxBufferPoolSize = binding1.MaxBufferPoolSize


        Dim maxReceivedMessageSize = binding1.MaxReceivedMessageSize

    Dim messageEncoding As WSMessageEncoding = binding1.MessageEncoding

    Dim proxyAddress As Uri = binding1.ProxyAddress

    Dim readerQuotas As XmlDictionaryReaderQuotas = binding1.ReaderQuotas

    Dim reliableSession As OptionalReliableSession = binding1.ReliableSession

        Dim scheme = binding1.Scheme

        Dim textEncoding = binding1.TextEncoding

        Dim transactionFlow = binding1.TransactionFlow

        Dim useDefaultWebProxy = binding1.UseDefaultWebProxy

    Dim bindingElements As BindingElementCollection = binding1.CreateBindingElements()

        ' Set WSHttpBinding binding property values
        binding1.Name = "Binding1"
        binding1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
        binding1.Security.Mode = SecurityMode.Message
        binding1.ReliableSession.Enabled = False
        binding1.TransactionFlow = False
       ' binding1.Security.Message.DefaultProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

        ' Enumerate properties of the binding1.
        Console.WriteLine("WSHttpBinding binding1 properties:")
        Console.WriteLine("      - name:" & Constants.vbTab + Constants.vbTab + Constants.vbTab & "{0}", binding1.Name)
        Console.WriteLine("      - hostname comparison:" & Constants.vbTab & "{0}", binding1.HostNameComparisonMode)
        Console.WriteLine("      - security mode:" & Constants.vbTab + Constants.vbTab & "{0}", binding1.Security.Mode)
        Console.WriteLine("      - RM enabled:" & Constants.vbTab + Constants.vbTab & "{0}", binding1.ReliableSession.Enabled)
        Console.WriteLine("      - transaction flow:" & Constants.vbTab & "{0}", binding1.TransactionFlow)
        'Console.WriteLine("      - message security:\t{0}", binding1.Security.Message.DefaultProtectionLevel);
        Console.WriteLine("      - transport scheme:" & Constants.vbTab & "{0}", binding1.Scheme)
        Console.WriteLine("      - max message size:" & Constants.vbTab & "{0}", binding1.MaxReceivedMessageSize)
        Console.WriteLine("      - default text encoding:" & Constants.vbTab & "{0}", binding1.TextEncoding)
        Console.WriteLine()

        ' Create a WSFederationBinding with a message security mode
        ' and with a reliable session enabled.
        Dim binding3 As New WSFederationHttpBinding(WSFederationHttpSecurityMode.Message, True)

        ' Enumerate properties of the binding2.
        Console.WriteLine("WSFederationBinding binding3 properties:")
        Console.WriteLine("      - security mode:" & Constants.vbTab + Constants.vbTab & "{0}", binding3.Security.Mode)
        Console.WriteLine("      - RM enabled:" & Constants.vbTab + Constants.vbTab & "{0}", binding3.ReliableSession.Enabled)
        Console.WriteLine()
        Console.WriteLine("Press <ENTER> to terminate.")
        Console.ReadLine()

    End Sub

Private Shared Sub SnippetReceiveSynchronously()
    Dim binding As New WSHttpBinding()
    Dim s As IBindingRuntimePreferences = binding.GetProperty(Of IBindingRuntimePreferences) (New BindingParameterCollection())
        Dim receiveSynchronously = s.ReceiveSynchronously

End Sub

End Class

注解

WSHttpBindingBase 为绑定提供用于配置安全、可靠和可互操作的 Web 服务的一些基本功能,例如,由适合于非双工服务协定的 WSHttpBinding(更具体来说,是支持 WS 联合协议的可靠、可互操作的 WSFederationHttpBinding)实现的功能。

默认情况下,它会生成一个运行时堆栈,该堆栈使用 WS 安全性来实现消息安全性和身份验证,使用 HTTP 来进行消息传递,并且使用文本/XML 消息编码功能。 该堆栈经过配置后还可以使用 WS-ReliableMessaging 以保证可靠性。

通过使用可选的 reliableSessionEnabled 参数,可以配置 WS-ReliableMessaging 的用法。

构造函数

WSHttpBindingBase()

初始化 WSHttpBindingBase 类的新实例。

WSHttpBindingBase(Boolean)

用一个值初始化 WSHttpBindingBase 类的新实例,该值指定是否已启用可靠会话。

属性

BypassProxyOnLocal

获取或设置一个值,该值指示是否跳过代理服务器而使用本地地址。

CloseTimeout

获取或设置在传输引发异常之前可用于关闭连接的时间间隔。

(继承自 Binding)
EnvelopeVersion

获取此绑定处理的消息将要使用的 SOAP 版本。

HostNameComparisonMode

获取或设置一个值,该值指示在对 URI 进行匹配时,是否使用主机名来访问服务。

MaxBufferPoolSize

获取或设置可为缓冲区管理器分配的最大内存量(以字节为单位),该管理器管理使用此绑定的终结点所需的缓冲区。

MaxReceivedMessageSize

获取或设置绑定可处理的消息的最大大小(以字节为单位)。

MessageEncoding

获取或设置一个值,该值指示是使用 MTOM 还是文本/XML 对 SOAP 消息进行编码。

MessageVersion

获取由绑定所配置的客户端和服务使用的消息版本。

(继承自 Binding)
Name

获取或设置绑定的名称。

(继承自 Binding)
Namespace

获取或设置绑定的 XML 命名空间。

(继承自 Binding)
OpenTimeout

获取或设置在传输引发异常之前可用于打开连接的时间间隔。

(继承自 Binding)
ProxyAddress

获取或设置 HTTP 代理的 URI 地址。

ReaderQuotas

获取或设置可由配置了此绑定的终结点处理的 SOAP 消息的复杂性约束。

ReceiveTimeout

获取或设置连接在撤消之前保持非活动状态的最大时间间隔,在此时间间隔内未接收任何应用程序消息。

(继承自 Binding)
ReliableSession

获取一个对象,当使用系统提供的一个绑定时,该对象可提供对可用的可靠会话绑定元素属性的便捷访问。

Scheme

获取用此绑定配置的通道和侦听器的 URI 传输方案。

SendTimeout

获取或设置在传输引发异常之前可用于完成写入操作的时间间隔。

(继承自 Binding)
TextEncoding

获取或设置用于消息文本的字符编码。

TransactionFlow

获取或设置一个值,该值指示此绑定是否应支持流动 WS-Transactions。

UseDefaultWebProxy

获取或设置一个值,该值指示是否应使用系统的自动配置 HTTP 代理(如果可用)。

方法

BuildChannelFactory<TChannel>(BindingParameterCollection)

在客户端上生成通道工厂堆栈,此通道工厂堆栈创建具有指定类型的通道并满足绑定参数集合所指定的功能。

(继承自 Binding)
BuildChannelFactory<TChannel>(Object[])

在客户端上生成通道工厂堆栈,该通道工厂堆栈创建具有指定类型的通道并满足对象数组所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足绑定参数集合所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection)

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
BuildChannelListener<TChannel>(Uri, String, Object[])

在服务上生成通道侦听器,该通道侦听器接受具有指定类型的通道并满足所指定的功能。

(继承自 Binding)
CanBuildChannelFactory<TChannel>(BindingParameterCollection)

返回一个值,该值指示当前绑定是否可以在客户端上生成满足指定绑定参数集合的通道工厂堆栈。

(继承自 Binding)
CanBuildChannelFactory<TChannel>(Object[])

返回一个值,该值指示当前绑定是否可以在客户端上生成满足对象数组所指定的需求的通道工厂堆栈。

(继承自 Binding)
CanBuildChannelListener<TChannel>(BindingParameterCollection)

返回一个值,该值指示当前绑定是否可以在服务上生成满足指定绑定参数集合的通道侦听器堆栈。

(继承自 Binding)
CanBuildChannelListener<TChannel>(Object[])

返回一个值,该值指示当前绑定是否可以在服务上生成满足对象数组所指定的条件的通道侦听器堆栈。

(继承自 Binding)
CreateBindingElements()

返回一个包含在当前绑定中的已排序的绑定元素集合。

CreateMessageSecurity()

在派生类中实现时,从当前绑定返回 SecurityBindingElement

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetProperty<T>(BindingParameterCollection)

从绑定堆栈的适当层返回所请求的类型化对象(如果存在)。

(继承自 Binding)
GetTransport()

在派生类中实现时,从当前绑定返回传输绑定元素。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ShouldSerializeName()

返回是否应序列化绑定名称。

(继承自 Binding)
ShouldSerializeNamespace()

返回是否应序列化绑定命名空间。

(继承自 Binding)
ShouldSerializeReaderQuotas()

返回一个值,该值指示 ReaderQuotas 属性是否已更改,不再是默认值且应对其进行序列化。

ShouldSerializeReliableSession()

返回一个值,该值指示 ReliableSession 属性是否已更改,不再是默认值且应对其进行序列化。

ShouldSerializeTextEncoding()

返回一个值,该值指示 TextEncoding 属性是否已更改,不再是默认值且应对其进行序列化。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IBindingRuntimePreferences.ReceiveSynchronously

获取一个值,该值指示是同步处理传入请求还是异步处理传入请求。

适用于