如何通过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. Quartz.NET总结(四)Quartz 远程调度

    前面篇已经介绍了Quartz.NET的配置,使用和Cron表达式表达式的写法.基本上后台的定时任务的定时执行已经完成,并能正确的按照执行计划,执行相关的job . 然后,如果任务需要更新,停止某个任务 ...

  2. PowerDesigner连接Oracle并导出表结构

    环境:Oracle 11G(远程) + win32_11gR2_client + PowerDesigner 15 一.下载.安装.配置 1.下载地址 win32_11gR2_client客户端下载地 ...

  3. 237. Delete Node in a Linked List

    在链接列表中删除节点. 编写一个函数来删除单链表中的一个节点(除了尾部),只提供对该节点的访问..假设链表是1 - > 2 - > 3 > 4,并给出了具有值为3的节点, 链表应该成 ...

  4. 浅谈ListView滑动隐藏显示ToolBar

    引言 在App日益追求体验的时代,优秀的用户体验往往会使产品脱颖而出.今天我们就来介绍一种简单的滑动ListView来显示或者隐藏ToolBar的功能. 布局文件 下面我们来看一下这个主界面的布局文件 ...

  5. Input输入框输入银行卡号自动空格

    input输入框是表格中用都最多的,像输入手机,密码,银行卡号的,很多对于输入银行卡号是没有处理的,比如这样~~ 看起来是不是一团乱麻,, 眼睛瞬间一片漆黑~  如果是这样,会不会好很多呢~~ 其实逻 ...

  6. 关于ubuntu下sublime text 3 的安装和中文配置问题

    一.sublime text 3 在ubuntu 16.04下的安装过程 1)首先下载sublime text 3 的tar包 $ wget https://download.sublimetext. ...

  7. python多种格式数据加载、处理与存储

    多种格式数据加载.处理与存储 实际的场景中,我们会在不同的地方遇到各种不同的数据格式(比如大家熟悉的csv与txt,比如网页HTML格式,比如XML格式),我们来一起看看python如何和这些格式的数 ...

  8. Error:Excepted resource of type id

    This inspection looks at Android API calls that have been annotated with various support annotations ...

  9. spark 官方文档(1)——提交应用程序

    Spark版本:1.6.2 spark-submit提供了在所有集群平台提交应用的统一接口,你不需要因为平台的迁移改变配置.Spark支持三种集群:Standalone.Apache Mesos和Ha ...

  10. scanf_s

    很多带“_s”后缀的函数是为了让原版函数更安全,传入一个和参数有关的大小值,避免引用到不存在的元素,有时hacker可以利用原版的不安全性黑掉系统 例如: ANSI C中没有scanf_s(),只有s ...