BasicHttpBinding 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 BasicHttpBinding 類別的新執行個體。
多載
BasicHttpBinding() |
初始化 BasicHttpBinding 類別的新執行個體。 |
BasicHttpBinding(BasicHttpSecurityMode) |
使用由繫結所使用之安全性的指定類型,初始化 BasicHttpBinding 類別的新執行個體。 |
BasicHttpBinding(String) |
使用由組態名稱指定的繫結,初始化 BasicHttpBinding 類別的新執行個體。 |
BasicHttpBinding()
初始化 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)
使用由繫結所使用之安全性的指定類型,初始化 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