You can expose the service in two different endpoints. the SOAP one can use the binding that support SOAP e.g. basicHttpBinding, the RESTful one can use the webHttpBinding. I assume your REST service will be in JSON, in that case, you need to configure the two endpoints with the following behaviour configuration

  1. <endpointBehaviors>
  2. <behavior name="jsonBehavior">
  3. <enableWebScript/>
  4. </behavior>
  5. </endpointBehaviors>

  An example of endpoint configuration in your scenario is

  1. <services>
  2. <service name="TestService">
  3. <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
  4. <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="ITestService"/>
  5. </service>
  6. </services>

  

so, the service will be available at

Apply [WebGet] to the operation contract to make it RESTful. e.g.

  1. public interface ITestService
  2. {
  3. [OperationContract]
  4. [WebGet]
  5. string HelloWorld(string text)
  6. }

  

Note, if the REST service is not in JSON, parameters of the operations can not contain complex type.

Reply to the post for SOAP and RESTful POX(XML)

For plain old XML as return format, this is an example that would work both for SOAP and XML

  1. [ServiceContract(Namespace = "http://test")]
  2. public interface ITestService
  3. {
  4. [OperationContract]
  5. [WebGet(UriTemplate = "accounts/{id}")]
  6. Account[] GetAccount(string id);
  7. }

  POX behavior for REST Plain Old XML

  1. <behavior name="poxBehavior">
  2. <webHttp/>
  3. </behavior>

  Endpoints

  1. <services>
  2. <service name="TestService">
  3. <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
  4. <endpoint address="xml" binding="webHttpBinding" behaviorConfiguration="poxBehavior" contract="ITestService"/>
  5. </service>
  6. </services>

  

Service will be available at

REST request try it in browser,

http://www.example.com/xml/accounts/A123

SOAP request client endpoint configuration for SOAP service after adding the service reference,

  1. <client>
  2. <endpoint address="http://www.example.com/soap" binding="basicHttpBinding"
  3. contract="ITestService" name="BasicHttpBinding_ITestService" />
  4. </client>

  in C#

  1. TestServiceClient client = new TestServiceClient();
  2. client.GetAccount("A123");

  Another way of doing it is to expose two different service contract and each one with specific configuration. This may generate some duplicates at code level, however at the end of the day, you want to make it working.

WCF 添加 RESTful 支持,适用于 IIS、Winform、cmd 宿主的更多相关文章

  1. IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android apk下载的MIME 设置 苹果ISO .ipa下载mime 设置

    原文:IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android apk下载的MIME 设置 苹果ISO .ipa下载mime 设置 站点--右键属性--http头 ...

  2. [老老实实学WCF] 第三篇 在IIS中寄存服务

    老老实实学WCF 第三篇 在IIS中寄宿服务 通过前两篇的学习,我们了解了如何搭建一个最简单的WCF通信模型,包括定义和实现服务协定.配置服务.寄宿服务.通过添加服务引用的方式配置客户端并访问服务.我 ...

  3. (转) [老老实实学WCF] 第三篇 在IIS中寄存服务

    第三篇 在IIS中寄宿服务 通过前两篇的学习,我们了解了如何搭建一个最简单的WCF通信模型,包括定义和实现服务协定.配置服务.寄宿服务.通过添加服务引用的方式配置客户端并访问服务.我们对WCF的编程生 ...

  4. WCF绑定netTcpBinding寄宿到IIS

    继续沿用上一篇随笔中WCF服务类库 Wettery.WcfContract.Services WCF绑定netTcpBinding寄宿到控制台应用程序 服务端 添加WCF服务应用程序 Wettery. ...

  5. WCF实现RESTFul Web Service

    共同学习了前面一些概念,终于开始正题了哈.RESTful的Web Service调用直观,返回的内容容易解析.这里先会描述一个简单的场景--Web Service提供一个方法来搜索个人信息,传入人名, ...

  6. WCF尝试创建与发布IIS(含问题描述)

    技术贴技术贴就直接讲技术来,客套的话我也不多说了,各位看官包涵包涵. 跟着园内高手一步一步发布成功,欣喜若狂之际,发个贴纪念纪念一下. 废话不多说,不正确之处,还望大家积极指出,共同进步.哈哈~~~ ...

  7. RESTful支持

    springmvc restful 支持 - 哎幽的成长 - CSDN博客http://blog.csdn.net/u012373815/article/details/47208345 RESTfu ...

  8. CEF3编译添加mp4支持(对应CefSharp63.0.3),chromium63(3239),附release下载

    编译环境需求(3239版本) win7或更高,64位 vs2017 15.3.2+ 默认位置安装 不需要安装附带的win10sdk,sdk单独装 Windows 10.0.15063.468 SDK ...

  9. Spring Boot 添加JSP支持【转】

    Spring Boot 添加JSP支持 大体步骤: (1)            创建Maven web project: (2)            在pom.xml文件添加依赖: (3)     ...

随机推荐

  1. 在centOS使用systemctl配置启动多个tomcat

    公司服务器使用的是阿里云CentOS7,CentOS7和CentOS6目前最大区别就是service变成了现在的systemctl,简单的查了一下并结合使用,发现systemctl功能上等同于6上面的 ...

  2. [转]kali中eth0网卡突然消失解决方案

    前言 不知道怎么kali的eth0网卡突然消失了.这可有点难受啊.在网上查找了一番找到了解决办法,特此记录. 问题   怎么办? 解决办法 首先使用ifconfig -a命令查看所有的网卡接口  发现 ...

  3. python流行的原因

    12~14年是云计算最火的几年,大批创业公司和巨头挤破头地进军云计算领域,大家都在做IAAS,最著名的云计算开源平台OpenStack 就是基于Python 开发的,为此催生出不少Python 岗位 ...

  4. 容易错的try

    配对方式一:try{}catch{}配对方法二:try{}catch{}finally{}配对方法三:try{}finally{}所以可用看出 catch和finally都不是必须的,try和catc ...

  5. 详细介绍如何在Eclipse中使用SVN

    一.在Eclipse中下载安装Subclipse插件   1 打开eclipse,在Help菜单中找到marketPlace,点击进入. 2 在搜索框Find中输入subclipse,点击右边的Go按 ...

  6. nova event

    nova处理neutron发送过来的event事件.暂时追踪nova event部分代码 tail -f /var/log/nova/nova-api.log  下面就是一个事件  Creating ...

  7. join和 Daemon守护线程

    一.前言 一个程序至少有一个主线程,主线程启动子线程后,它们之间并没有隶属关系.主线程和子线程执行是并行的,相互独立.主线程执行完毕后默认不等子线程执行结束就接着往下走了,如果有其他程序就会运行另外的 ...

  8. 【提权思路】绕过SecureRDP限制远程连接

    工具可以在百度上下载 直接步入正题 配置好的SecureRDP是限制远程登录的用户 原理是判断来访的计算机名是否在白名单中 如果不在,便出现如上图所示 网上也有绕过方法(https://weibo.c ...

  9. KMP 解决串的模式匹配问题

    初学KMP的时候,一直不得要领.后来学习AC自动机的时候,一下子明白了KMP实际上是AC自动机的特殊情况. 首先贴三段代码,一组是回溯法,暴力求解,另外两个是KMP串模式匹配 /* 回溯法字符串匹配算 ...

  10. ZOJ 3632 K - Watermelon Full of Water 优先队列优化DP

    K - Watermelon Full of Water Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld &am ...