如何通过WCF向外提供Restful的Service请看如下链接

http://www.cnblogs.com/mingmingruyuedlut/p/4223116.html

那么如何通过对web.config的配置,使原有的Service即符合HTTP又符合HTTPS呢?

请看如下具体步骤:

1):将上篇文章 http://www.cnblogs.com/mingmingruyuedlut/p/4223116.html 中的IIS对应的Site绑定80端口,并且添加HTTPS的443端口

2):保持其他不变,然后我们访问 http://localhost/UserService.svc 依旧可以看到我们所提供的Service是好用的,现在我们向web.config文件添加binding来实现HTTPS的配置

2.1):在system.ServiceModel节点中添加如下节点

    <bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>

2.2):然后在services节点中添加如下节点

          <endpoint address=""
binding="webHttpBinding"
bindingConfiguration="SecureWebBinding"
contract="EricSunWcfService.IUserService"
behaviorConfiguration="ESEndPointBehavior"/> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>

2.3):最终的配置文件为

<?xml version="1.0"?>
<configuration> <appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="EricSunWcfService.UserService" behaviorConfiguration="RESTBehaviour">
<endpoint address=""
binding="webHttpBinding"
contract="EricSunWcfService.IUserService"
behaviorConfiguration="ESEndPointBehavior"/>
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="SecureWebBinding"
contract="EricSunWcfService.IUserService"
behaviorConfiguration="ESEndPointBehavior"/> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RESTBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior> <behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ESEndPointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<!--<modules runAllManagedModulesForAllRequests="true"/>--> <modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers> </system.webServer> </configuration>

3):这样我们通过URL-->  https://localhost/UserService.svc ,以及 http://www.cnblogs.com/mingmingruyuedlut/p/4223116.html 这篇文章中的方法去测试我们提供的Service是好用的

至此如何添加https的访问节点就搞定了~~

更多信息请看如下链接:

https://nirajrules.wordpress.com/2011/04/29/wcf-rest-over-https/

通过配置web.config使WCF向外提供HTTPS的Restful Service的更多相关文章

  1. 配置子目录Web.config使其消除继承,用虚拟目录创建多个网站的方法

    来源:http://www.wtnzone.com/post/2011/02/20/Set-Web-Config-to-Turn-Inheritance-Off.aspx ASP.NET提供了强大的W ...

  2. 配置子目录Web.config使其消除继承,iis7.0设置路由

    iis7.0设置路由 ,url转向,伪静态 <system.webServer>      <modules runAllManagedModulesForAllRequests=& ...

  3. asp.net配置web.config支持jQuery.Uploadify插件上传大文件

    配置web.config有两处地方需要配置,分别是集成模式和经典模式. 集成模式: <!--文件上传大小设置--> <httpRuntime requestValidationMod ...

  4. asp.net权限控制配置web.config

    项目下 有三个文件夹 A,B,C 验正方式是 Forms 验正 我要设置他们的访问权限为, A,匿名可访问 B,普通用户授权后才能访问 C,只允许管理员访问 <configuration> ...

  5. WCF学习笔记一之通过配置web.config可以通过http访问接口

    一.准备 这里涉及到三个文件,现在只是简单的把代码贴出来,后面再详细的讲一下. 三个文件分别是(都是wcf服务应用程序项目下的): 1.IService1.cs 2.Service1.svc 3.We ...

  6. asp.net mvc 应用Bundle(捆绑和微小)压缩技术 启用 BundleConfig 配置web.config

    从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了 [App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleCon ...

  7. asp.net项目配置Web.config,支持JSON

    VS2013新建的web项目不支持直接下载json文件,可以在项目的web.config下插入如下的配置信息. <configuration> <system.web> < ...

  8. 配置Web.config 元素CustomErrors

    一.customErrors 元素 属性 说明 defaultRedirect 指定出错时将浏览器定向到的默认 URL.如果未指定该属性,则显示一般性错误. 可选的属性. URL 可以是绝对的(如 w ...

  9. asp.net 配置 web.config 禁用VS2013自带的Browser Link功能

    我的字符被截断了 然后,我修改了下 web.config 的配置,在appSettings节点里加了这个,如下: <appSettings><add key="vs:Ena ...

随机推荐

  1. Eclipse换背景色

    上班后,长时间看代码,眼睛感觉有些疲惫,就想想如果能换个肤色就好了,于是在网上搜了一下,果真Eclipse提供了这个方面功能,心情小激动, 顿时感觉萌萌哒,于是乐呵呵的把肤色改了.在这感谢网上的亲们, ...

  2. Android中AIDL的理解与使用(二)——跨应用绑定Service并通信

    跨应用绑定Service并通信: 1.(StartServiceFromAnotherApp)AIDL文件中新增接口: void setData(String data); AppService文件中 ...

  3. centos7 cannot find a valid baseurl for repo base (转载)

    centos7 cannot find a valid baseurl for repo base     今天在虚拟机下安装centosmini版本,安装后第一件事就是yum update 但是有错 ...

  4. poj Flip Game 1753 (枚举)

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27005   Accepted: 11694 Descr ...

  5. [Machine Learning & Algorithm] 神经网络基础

    目前,深度学习(Deep Learning,简称DL)在算法领域可谓是大红大紫,现在不只是互联网.人工智能,生活中的各大领域都能反映出深度学习引领的巨大变革.要学习深度学习,那么首先要熟悉神经网络(N ...

  6. Sql Cursor example

    USE [EUC]GO/****** Object:  StoredProcedure [dbo].[SP_SME_QueryAuditLog]    Script Date: 02/05/2015 ...

  7. HTML DOM 之<textare>标签

    对于DOM元素节点textarea的value值,下面举例说一下. 1. <textarea><textarea> 2.<textarea> <textare ...

  8. BZOJ4318——OSU!

    1.题意:一个序列,连续的一段1对得分具有贡献,那么问期望得分 2.分析:一道裸的期望dp,那么新加入一个1,对答案的贡献为 直接暴力算出期望的平方和期望,每次dp的时候更新一下就好了 #includ ...

  9. bzoj2928: [Poi1999]飞弹

    惨啊…… 被卡常是一种什么感受&…… 很明显的分治. 我们首先可以找到所有点中的最低点,然后对所有点进行一次极角排序,选取一个点使得他各侧飞弹和地堡一样多,并对两侧继续进行分治. 很容易证明这 ...

  10. 手写一个allocator

    似乎就像是一个计算机原理的实践.. 首先介绍一下大多数操作系统的内存架构..对于某个程序它会认为自己是独占了整个系统的所有内存在运行的这样才能方便移植,因此人们搞出了虚拟内存和物理内存的区别,于是人们 ...