The wsTransportSecurity sample demonstrates the use of SSL transport security with the WSHttpBinding binding. By default, the wsHttpBinding binding provides HTTP communication. When configured for transport security, the binding supports HTTPS communication. This sample is based on the Getting Started that implements a calculator service. The wsHttpBinding is specified and configured in the application configuration files for the client and service.
Note
The set-up procedure and build instructions for this sample are located at the end of this topic.
The program code in the sample is identical to that of the Getting Started service. You must create a certificate and assign it by using the Web Server Certificate Wizard before building and running the sample. The endpoint definition and binding definition in the configuration file settings enable Transport security mode, as shown in the following sample configuration for the client.
<system.serviceModel>
<client>
<!-- this endpoint has an https: address -->
<endpoint address="https://localhost/servicemodelsamples/service.svc" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.TransportSecurity.ICalculator"/>
</client>
<bindings>
<wsHttpBinding>
<!-- configure wsHttpbinding with Transport security mode
and clientCredentialType as None -->
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
The address specified uses the https:// scheme. The binding configuration sets the security mode to Transport. The same security mode must be specified in the service's Web.config file.
Because the certificate used in this sample is a test certificate created with Makecert.exe, a security alert appears when you try to access an https: address, such as https://localhost/servicemodelsamples/service.svc, from your browser. To allow the Windows Communication Foundation (WCF) client to work with a test certificate in place, some additional code has been added to the client to suppress the security alert. This code, and the accompanying class, is not required when using production certificates.
// This code is required only for test certificates like those created by Makecert.exe.
PermissiveCertificatePolicy.Enact("CN=ServiceModelSamples-HTTPS-Server");
When you run the sample, the operation requests and responses are displayed in the client console window. Press ENTER in the client window to shut down the client.
As an Information Security Administrator, you plan and implement information security of sensitive data by using Microsoft Purview and related services. You’re responsible for mitigating risks by protecting data inside collaboration environments that are managed by Microsoft 365 from internal and external threats and protecting data used by AI services. You also implement information protection, data loss prevention, retention, insider risk management, and manage information security alerts and activities.
Defines a secure, reliable, interoperable HTTP binding suitable for non-duplex service contracts, which implements WS-Reliable Messaging and WS-Security.
Find out how to select the right binding for your security needs. The system-provided bindings included with WCF provide a quick way to program WCF applications.