BasicHttpBinding 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 Windows Communication Foundation (WCF)服务可用来配置和公开终结点的绑定,这些终结点将能够与基于 ASMX 的 Web 服务和客户端以及其他符合 WS-I Basic Profile 1.1 的服务进行通信。
public ref class BasicHttpBinding : System::ServiceModel::HttpBindingBase
public ref class BasicHttpBinding : System::ServiceModel::Channels::Binding, System::ServiceModel::Channels::IBindingRuntimePreferences
public class BasicHttpBinding : System.ServiceModel.HttpBindingBase
public class BasicHttpBinding : System.ServiceModel.Channels.Binding, System.ServiceModel.Channels.IBindingRuntimePreferences
type BasicHttpBinding = class
inherit HttpBindingBase
type BasicHttpBinding = class
inherit Binding
interface IBindingRuntimePreferences
type BasicHttpBinding = class
inherit HttpBindingBase
interface IBindingRuntimePreferences
Public Class BasicHttpBinding
Inherits HttpBindingBase
Public Class BasicHttpBinding
Inherits Binding
Implements IBindingRuntimePreferences
- 继承
- 继承
- 派生
- 实现
示例
下面的示例演示如何在应用程序配置文件中配置 BasicHttpBinding。
下面的示例演示如何以编程方式配置 BasicHttpBinding。
[ServiceContract(Namespace = "http://UE.ServiceModel.Samples")]
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);
}
public class CalculatorService : ICalculator
{
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;
}
public double Subtract(double n1, double n2)
{
double result = n1 - n2;
Console.WriteLine("Received Subtract({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public double Multiply(double n1, double n2)
{
double result = n1 * n2;
Console.WriteLine("Received Multiply({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public double Divide(double n1, double n2)
{
double result = n1 / n2;
Console.WriteLine("Received Divide({0},{1})", n1, n2);
Console.WriteLine("Return: {0}", result);
return result;
}
public static void Main()
{
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();
}
}
<ServiceContract(Namespace:="http://UE.ServiceModel.Samples")> _
Public Interface ICalculator
<OperationContract()> _
Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double
<OperationContract()> _
Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double
End Interface
' Service class which implements the service contract.
' Added code to write output to the console window
Public Class CalculatorService
Implements ICalculator
Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Add
Dim result As Double = n1 + n2
Console.WriteLine("Received Add({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Subtract
Dim result As Double = n1 - n2
Console.WriteLine("Received Subtract({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Multiply
Dim result As Double = n1 * n2
Console.WriteLine("Received Multiply({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Divide
Dim result As Double = n1 / n2
Console.WriteLine("Received Divide({0},{1})", n1, n2)
Console.WriteLine("Return: {0}", result)
Return result
End Function
Public Shared Sub Main()
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
End Sub
End Class
注解
BasicHttpBinding 使用 HTTP 作为传输协议用于发送 SOAP 1.1 消息。 服务可以使用此绑定来公开符合 WS-I BP 1.1 标准的终结点,如 ASMX 客户端访问的终结点。 同样,客户端可以使用BasicHttpBinding服务与符合 WS-I BP 1.1 的服务进行通信,例如 ASMX Web 服务或 Windows Communication Foundation (WCF) 配置BasicHttpBinding的服务。
默认情况下,安全性处于禁用状态,但是通过在 BasicHttpSecurityMode 构造函数中将 None 设置为不同于 BasicHttpBinding(BasicHttpSecurityMode) 的值,可以添加安全性。 默认情况下,它使用“Text”消息编码和 UTF-8 文本编码。
构造函数
BasicHttpBinding() |
初始化 BasicHttpBinding 类的新实例。 |
BasicHttpBinding(BasicHttpSecurityMode) |
通过绑定所使用的指定安全性类型初始化 BasicHttpBinding 类的新实例。 |
BasicHttpBinding(String) |
使用由配置名称指定的绑定初始化 BasicHttpBinding 类的新实例。 |
属性
AllowCookies |
获取或设置一个值,该值指示客户端是否接受 Cookie 并根据今后的请求传播 Cookie。 |
AllowCookies |
获取或设置一个值,该值指示客户端是否接受 Cookie 并根据今后的请求传播 Cookie。 (继承自 HttpBindingBase) |
BypassProxyOnLocal |
获取或设置一个值,该值指示是否跳过代理服务器而使用本地地址。 |
BypassProxyOnLocal |
获取或设置一个值,该值指示是否跳过代理服务器而使用本地地址。 (继承自 HttpBindingBase) |
CloseTimeout |
获取或设置在传输引发异常之前可用于关闭连接的时间间隔。 (继承自 Binding) |
EnableHttpCookieContainer |
已过时。
获取或设置一个值,该值指示是否启用 HTTP Cookie 容器。 |
EnvelopeVersion |
获取此绑定处理的消息将要使用的 SOAP 版本。 |
EnvelopeVersion |
获取此绑定处理的消息将要使用的 SOAP 版本。 (继承自 HttpBindingBase) |
HostNameComparisonMode |
获取或设置一个值,该值指示在对 URI 进行匹配时,是否使用主机名来访问服务。 |
HostNameComparisonMode |
获取或设置一个值,该值指示在对 URI 进行匹配时,是否使用主机名来访问服务。 (继承自 HttpBindingBase) |
MaxBufferPoolSize |
获取或设置为从通道接收消息的消息缓冲区管理器分配并供其使用的最大内存量(以字节为单位)。 |
MaxBufferPoolSize |
获取或设置为从通道接收消息的消息缓冲区管理器分配并供其使用的最大内存量(以字节为单位)。 (继承自 HttpBindingBase) |
MaxBufferSize |
获取或设置缓冲区的最大大小(以字节为单位),该缓冲区用于接收来自通道的消息。 |
MaxBufferSize |
获取或设置缓冲区的最大大小(以字节为单位),该缓冲区用于接收来自通道的消息。 (继承自 HttpBindingBase) |
MaxReceivedMessageSize |
获取或设置配置了此绑定配置的通道上可以接收的消息的最大大小(以字节为单位)。 |
MaxReceivedMessageSize |
获取或设置配置了此绑定配置的通道上可以接收的消息的最大大小(以字节为单位)。 (继承自 HttpBindingBase) |
MessageEncoding |
获取或设置是使用 MTOM 还是文本对 SOAP 消息进行编码。 |
MessageVersion |
获取由绑定所配置的客户端和服务使用的消息版本。 (继承自 Binding) |
Name |
获取或设置绑定的名称。 (继承自 Binding) |
Namespace |
获取或设置绑定的 XML 命名空间。 (继承自 Binding) |
OpenTimeout |
获取或设置在传输引发异常之前可用于打开连接的时间间隔。 (继承自 Binding) |
ProxyAddress |
获取或设置 HTTP 代理的 URI 地址。 |
ProxyAddress |
获取或设置 HTTP 代理的 URI 地址。 (继承自 HttpBindingBase) |
ReaderQuotas |
获取或设置可由配置了此绑定的终结点处理的 SOAP 消息的复杂性约束。 |
ReaderQuotas |
获取或设置可由配置了此绑定的终结点处理的 SOAP 消息的该复杂性约束。 (继承自 HttpBindingBase) |
ReceiveTimeout |
获取或设置连接在撤消之前保持非活动状态的最大时间间隔,在此时间间隔内未接收任何应用程序消息。 (继承自 Binding) |
Scheme |
获取用此绑定配置的通道和侦听器的 URI 传输方案。 |
Scheme |
获取用此绑定配置的通道和侦听器的 URI 传输方案。 (继承自 HttpBindingBase) |
Security |
获取与此绑定一起使用的安全类型。 |
SendTimeout |
获取或设置在传输引发异常之前可用于完成写入操作的时间间隔。 (继承自 Binding) |
TextEncoding |
获取或设置用于消息文本的字符编码。 |
TextEncoding |
获取或设置用于消息文本的字符编码。 (继承自 HttpBindingBase) |
TransferMode |
获取或设置一个值,该值指示是通过缓冲处理还是流处理来发送消息。 |
TransferMode |
获取或设置一个值,该值指示是通过缓冲处理还是流处理来发送消息。 (继承自 HttpBindingBase) |
UseDefaultWebProxy |
获取或设置一个值,该值指示是否应使用系统的自动配置 HTTP 代理(如果可用)。 |
UseDefaultWebProxy |
获取或设置一个值,该值指示是否应使用系统的自动配置 HTTP 代理(如果可用)。 (继承自 HttpBindingBase) |
方法
显式接口实现
IBindingRuntimePreferences.ReceiveSynchronously |
获取一个值,该值指示是同步处理传入请求还是异步处理传入请求。 |
IBindingRuntimePreferences.ReceiveSynchronously |
获取一个值,该值指示是同步处理传入请求还是异步处理传入请求。 (继承自 HttpBindingBase) |