WCF Services Sample: Config WCF services over HTTPS only

In my previous blogs I have introduced how to create a WCF service and host it in IIS, and config it over both Http and Https. In this blog I would like to move forward -- config the service work over only HTTPS. I will still use that sample project.

1. Setup Web Application with SSL Required

Open the IIS Manager, Select "ServiceHost" web application under the default web site as shown below.

iis-ssl-required-1.jpg

Double-click "SSL Settings" on the right frame, the "SSL Settings" window is shown as below.

iis-ssl-required-2.jpg

make sure the "Require SSL" check-box is checked and click the "Apply" button on the top-right of the window.

Now the WCF service hosting site is configed to access via HTTPS only.

2. Change the Web.config

At this point if you test the service via https, it will not activate correctly.

wcf-service-ssl-required-error.jpg

The reason is that we have config the service over HTTP and HTTPS, and now HTTP protocol is forbidden. Let's modify the Web.config file. We need to remove the element and the element for Http. The Web.config now looks like such:

 
 












<!-- Service Endpoints --&gt












3. Run the Application From VS2008

The Silverlight client code looks like:

 
 

EndpointAddress address = new EndpointAddress("https://yuzhangqi01/ServiceHost/Service1.svc/ssl");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

proxy = new Service1Client(binding, address);

Press F5 in Vs2008 and test the application, it returns what we expected.

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13651903/viewspace-1033981/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13651903/viewspace-1033981/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值