[WCF] Restful 自定义宿主
IPersonRetriever:
/** 由SharpDevelop创建。* 用户: Administrator* 日期: 2017/6/2* 时间: 22:13* * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;namespace WcfRESTful
{/// <summary>/// Description of IPersonRetriever./// </summary>[ServiceContract]public interface IPersonRetriever{[OperationContract][WebInvokeAttribute(UriTemplate = "Persons",Method="POST", ResponseFormat = WebMessageFormat.Json)]Person GetPerson();}[DataContract]public class Person{[DataMember]public string Name { get; set; }[DataMember]public int Age { get; set; }[DataMember]public string Birthday { get; set; }}
}
PersonRetriever:
/** 由SharpDevelop创建。* 用户: Administrator* 日期: 2017/6/2* 时间: 22:15* * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件*/
using System;
using System.ServiceModel.Web;namespace WcfRESTful
{/// <summary>/// Description of PersonRetriever./// </summary>public class PersonRetriever: IPersonRetriever{public Person GetPerson(){WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";return new Person { Name = "Test", Age = 22, Birthday = DateTime.Now.ToString("yyyy-mm-dd HH:MM:ss:ffff") };}}
}
Program :
/** 由SharpDevelop创建。* 用户: Administrator* 日期: 2017/6/2* 时间: 22:19* * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件*/
using System;
using System.ServiceModel;
using System.ServiceModel.Description;namespace WcfRESTful
{class Program{public static void Main(string[] args){Console.WriteLine("Hello World!");// TODO: Implement Functionality HereUri baseAddress = new Uri("http://127.0.0.1:9998/PersonRetriever");using (ServiceHost host = new ServiceHost(typeof(PersonRetriever), baseAddress)) {WebHttpBinding binding = new WebHttpBinding();ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IPersonRetriever), binding, baseAddress);WebHttpBehavior httpBehavior = new WebHttpBehavior();endpoint.Behaviors.Add(httpBehavior);host.Opened += delegate {Console.WriteLine("Hosted successfully.");};host.Open();Console.ReadLine();}Console.Write("Press any key to continue . . . ");Console.ReadKey(true);}}
}
截图 :
源码: http://files.cnblogs.com/files/Areas/WcfRESTful.zip
转载于:https://www.cnblogs.com/Areas/p/6935547.html
[WCF] Restful 自定义宿主相关推荐
- [转]构建基于WCF Restful Service的服务
本文转自:http://www.cnblogs.com/scy251147/p/3566638.html 前言 传统的Asmx服务,由于遵循SOAP协议,所以返回内容以xml方式组织.并且客户端需要添 ...
- WCF之自定义信道工厂,信道监听器
如果您对.NET远程处理或者是从事过有关Socket相关的编程,那么您可能会对以上两个概念不会很陌生.其实信道工厂和信道监听器的概念在.NET远程处理和Socket中就提到过,只是在WCF中的这两个概 ...
- IOS调用WCF提供的服务方法,但是方法的参数是WCF那边自定义的对象,这样有办法调用么,如果可以IOS应该怎么传参呢?请问有了解的么,...
最近做一个项目后端使用WCF接收Android手机拍照并带其它参数保存到服务器里:刚好把最近学习的WCF利用上,本以为是个比较简单的功能应该很好实现,没想到其中碰到不少问题,在网上搜索很久一直没有想到 ...
- silverlight 读取wcf服务 读取宿主端的config 良好的方法
在开发当中遇到很头疼的事情,就是每当要改动地图的服务的IP地址时,还要重新打开silverlight项目源代码,修改后重新编译,么么,这种是让人折磨呀.今天一天寻找方法,总算是解决了这个问题. 一.s ...
- Spring Boot validator参数验证restful自定义错误码响应
2019独角兽企业重金招聘Python工程师标准>>> 关于spring web应用中关于如何使用 Bean Validation API和hibernate-validator的文 ...
- 在HTML中使用WCF RESTful上传文件
说明 在HTML中上传文件时会为文件内容加入一头一尾,如下所示: -----------------------8cc0b8cfcfd5ed2 Content-Disposition: form-da ...
- oracle spool文件名+系统时间,Oracle Spool详解
转自:http://blog.sina.com.cn/s/blog_6bccf0360101hzsh.html 1.spool的作用是什么? spool的作用可以用一句话来描述:在sqlplus中用来 ...
- 自定义托管宿主WCF解决方案开发配置过程详解
上一节<WCF分布式框架基础概念>我们介绍了WCF服务的概念和通信框架模型,并给出了基于自定义托管服务的WCF程序的实现代码.考虑到WCF分布式开发项目中关于托管宿主服务配置和客户端添加引 ...
- WCF分布式安全开发实践(6):传输安全模式之自定义X509Certificate证书验证
今天继续WCF分布式安全开发实践(6):传输安全模式之自定义X509Certificate证书验证.本文介绍的内容主要是:主要是传输安全模式的UserNamePassword身份验证方式,基于WSHt ...
最新文章
- 传智播客C/C++各种开发环境搭建视频工具文档免费教程
- HM16.0之帧间预测——xCheckRDCostInter()函数
- php丢弃,在IIS 7.5中,PHP吓坏了(连接丢失,连接被丢弃)
- SpringBoot中oauth2.0学习之服务端配置快速上手
- Golang——枚举(iota)的使用
- select自定义箭头样式
- mysql innodb事务中 出现_MySql InnoDB事务死锁问题
- 使用基于JSON的实体在C#中缓存远程数据
- spellChecker 拼写检查
- Javascript数据类型共有六种
- Unix中使用MeteoInfo - Xmanager设置
- springboot配置手动提交_Spring Boot 入门教程 | 图文讲解
- Windows server 2003 下载
- 如何让自己电脑的鼠标指针变的更炫酷来看看这个吧
- 关于java架构心得
- Axure可视化原型模板+大数据图表组件 提升您的设计效率 做出甲方买不起的样子
- 第二十四讲 一阶常微分方程组
- OCI(Ocean Cycle) 海洋循环回收认证是什么?
- Couch的MapReduce查询
- mac pe 制作教程