BasicHttpBinding 构造函数

定义

初始化 BasicHttpBinding 类的新实例。

重载

BasicHttpBinding()

初始化 BasicHttpBinding 类的新实例。

BasicHttpBinding(BasicHttpSecurityMode)

通过绑定所使用的指定安全性类型初始化 BasicHttpBinding 类的新实例。

BasicHttpBinding(String)

使用由配置名称指定的绑定初始化 BasicHttpBinding 类的新实例。

BasicHttpBinding()

Source:
BasicHttpBinding.cs
Source:
BasicHttpBinding.cs
Source:
BasicHttpBinding.cs

初始化 BasicHttpBinding 类的新实例。

public:
 BasicHttpBinding();
public BasicHttpBinding ();
Public Sub New ()

示例

        BasicHttpBinding binding = new BasicHttpBinding();
        binding.Name = "binding1";
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.Security.Mode = BasicHttpSecurityMode.None;

        Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
        Uri address = new Uri("http://localhost:8000/servicemodelsamples/service/calc");

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

        serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

        // 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();
Dim binding As BasicHttpBinding = New BasicHttpBinding()
binding.Name = "binding1"
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
binding.Security.Mode = BasicHttpSecurityMode.None

Dim baseAddress As Uri = New Uri("http://localhost:8000/servicemodelsamples/service")
Dim address As Uri = New Uri("http://localhost:8000/servicemodelsamples/service/calc")

' Create a ServiceHost for the CalculatorService type and provide the base address.
Using serviceHost As ServiceHost = New ServiceHost(GetType(CalculatorService), baseAddress)

    serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, address)

    ' Open the ServiceHost 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 ServiceHost to shutdown the service.
    serviceHost.Close()
End Using

注解

所用的 BasicHttpSecurityMode 的默认值为 None,该值指定不保证 SOAP 消息的安全并且不对客户端进行身份验证。

适用于

BasicHttpBinding(BasicHttpSecurityMode)

Source:
BasicHttpBinding.cs
Source:
BasicHttpBinding.cs
Source:
BasicHttpBinding.cs

通过绑定所使用的指定安全性类型初始化 BasicHttpBinding 类的新实例。

public:
 BasicHttpBinding(System::ServiceModel::BasicHttpSecurityMode securityMode);
public BasicHttpBinding (System.ServiceModel.BasicHttpSecurityMode securityMode);
new System.ServiceModel.BasicHttpBinding : System.ServiceModel.BasicHttpSecurityMode -> System.ServiceModel.BasicHttpBinding
Public Sub New (securityMode As BasicHttpSecurityMode)

参数

securityMode
BasicHttpSecurityMode

BasicHttpSecurityMode 的值,该值指定在 SOAP 消息和客户端中使用的安全类型。

示例

        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Message);
        binding.Name = "binding1";
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        BasicHttpSecurityMode sMode = binding.Security.Mode;

        Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
        Uri address = new Uri("http://localhost:8000/servicemodelsamples/service/calc");

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

        serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

        // 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();
Dim binding As BasicHttpBinding = New BasicHttpBinding(BasicHttpSecurityMode.Message)
binding.Name = "binding1"
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
binding.Security.Mode = BasicHttpSecurityMode.None

Dim baseAddress As Uri = New Uri("http://localhost:8000/servicemodelsamples/service")
Dim address As Uri = New Uri("http://localhost:8000/servicemodelsamples/service/calc")

' Create a ServiceHost for the CalculatorService type and provide the base address.
Using serviceHost As ServiceHost = New ServiceHost(GetType(CalculatorService), baseAddress)

    serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, address)

    ' Open the ServiceHost 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 ServiceHost to shutdown the service.
    serviceHost.Close()
End Using

注解

所用的 BasicHttpSecurityMode 的默认值为 None,该值指定不保证 SOAP 消息的安全并且不对客户端进行身份验证。

适用于

BasicHttpBinding(String)

使用由配置名称指定的绑定初始化 BasicHttpBinding 类的新实例。

public:
 BasicHttpBinding(System::String ^ configurationName);
public BasicHttpBinding (string configurationName);
new System.ServiceModel.BasicHttpBinding : string -> System.ServiceModel.BasicHttpBinding
Public Sub New (configurationName As String)

参数

configurationName
String

BasicHttpBindingElement 的绑定配置名称。

例外

找不到配置名称为 configurationName 的绑定。

示例

此示例使用由配置名称“BasicHttpBinding”指定的绑定初始化新的 myBinding 类。 可在服务的配置文件中创建绑定部分。

BasicHttpBinding binding = new BasicHttpBinding("myBinding");
binding.Name = "binding1";
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.Security.Mode = BasicHttpSecurityMode.Message;

BasicHttpSecurity security = binding.Security;
BasicHttpMessageSecurity msgSecurity = security.Message;

SecurityAlgorithmSuite sas = msgSecurity.AlgorithmSuite;
BasicHttpMessageCredentialType credType = msgSecurity.ClientCredentialType;

Console.WriteLine("The algorithm suite used is {0}", sas.ToString());
Console.WriteLine("The client credential type used is {0}", credType.ToString());
Dim binding As BasicHttpBinding = New BasicHttpBinding()
binding.Name = "binding1"
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
binding.Security.Mode = BasicHttpSecurityMode.Message

Dim security As BasicHttpSecurity = binding.Security
Dim msgSecurity As BasicHttpMessageSecurity = security.Message

Dim sas As SecurityAlgorithmSuite = msgSecurity.AlgorithmSuite
Dim credType As BasicHttpMessageCredentialType = msgSecurity.ClientCredentialType

Console.WriteLine("The algorithm suite used is {0}", sas.ToString())
Console.WriteLine("The client credential type used is {0}", credType.ToString())

然后,在对 BasicHttpBinding 构造函数的调用中指定绑定配置的名称。

BasicHttpBinding binding = new BasicHttpBinding();
binding.Name = "binding1";
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.Security.Mode = BasicHttpSecurityMode.None;

Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
Uri address = new Uri("http://localhost:8000/servicemodelsamples/service/calc");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

    // 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();
}
Dim binding As BasicHttpBinding = New BasicHttpBinding("BasicBinding")
binding.Name = "binding1"
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
binding.Security.Mode = BasicHttpSecurityMode.None

Dim baseAddress As Uri = New Uri("http://localhost:8000/servicemodelsamples/service")
Dim address As Uri = New Uri("http://localhost:8000/servicemodelsamples/service/calc")

' Create a ServiceHost for the CalculatorService type and provide the base address.
Using serviceHost As ServiceHost = New ServiceHost(GetType(CalculatorService), baseAddress)

    serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, address)

    ' Open the ServiceHost 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 ServiceHost to shutdown the service.
    serviceHost.Close()
End Using

适用于