博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WCF 添加 RESTful 支持,适用于 IIS、Winform、cmd 宿主
阅读量:6295 次
发布时间:2019-06-22

本文共 1689 字,大约阅读时间需要 5 分钟。

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

  An example of endpoint configuration in your scenario is

  

so, the service will be available at

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

public interface ITestService{   [OperationContract]   [WebGet]   string HelloWorld(string text)}

  

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

[ServiceContract(Namespace = "http://test")]public interface ITestService{    [OperationContract]    [WebGet(UriTemplate = "accounts/{id}")]    Account[] GetAccount(string id);}

  POX behavior for REST Plain Old XML

  Endpoints

  

Service will be available at

REST request try it in browser,

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

  in C#

TestServiceClient client = new TestServiceClient();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.

 

转载地址:http://eytta.baihongyu.com/

你可能感兴趣的文章
webpack4+babel7+eslint+editorconfig+react-hot-loader 搭建react开发环境
查看>>
Maven 插件
查看>>
初探Angular6.x---进入用户编辑模块
查看>>
计算机基础知识复习
查看>>
【前端词典】实现 Canvas 下雪背景引发的性能思考
查看>>
大佬是怎么思考设计MySQL优化方案的?
查看>>
<三体> 给岁月以文明, 给时光以生命
查看>>
Android开发 - 掌握ConstraintLayout(九)分组(Group)
查看>>
springboot+logback日志异步数据库
查看>>
Typescript教程之函数
查看>>
Android 高效安全加载图片
查看>>
vue中数组变动不被监测问题
查看>>
3.31
查看>>
类对象定义 二
查看>>
收费视频网站Netflix:用户到底想要“点”什么?
查看>>
MacOS High Sierra 12 13系统转dmg格式
查看>>
关于再次查看已做的多选题状态逻辑问题
查看>>
动态下拉菜单,非hover
查看>>
政府安全资讯精选 2017年第十六期 工信部发布关于规范互联网信息服务使用域名的通知;俄罗斯拟建立备用DNS;Google打击安卓应用在未经同意情况下收集个人信...
查看>>
简单易懂的谈谈 javascript 中的继承
查看>>