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 Here Uri 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

[WCF] Restful 自定义宿主的更多相关文章

  1. Linux学习日记-WCF RestFul的部署(三)

    一.关于WCF 的部署 默认的wshttp风格的wcf是很容易部署上去的,但是这里给个建议尽量不要使用WCF的配置文件去部署尽管 我们都已经很熟悉了,在使用配置文件你会发现各种蛋疼的问题. 二.WCF ...

  2. 构建基于WCF Restful Service的服务

    前言 传统的Asmx服务,由于遵循SOAP协议,所以返回内容以xml方式组织.并且客户端需要添加服务端引用才能使用(虽然看到网络上已经提供了这方面的Dynamic Proxy,但是没有这种方式简便), ...

  3. 使用多种客户端消费WCF RestFul服务(四)——Jquery篇

    Jquery篇 互联网开发中少不了各类前端开发框架,其中JQUERY就是最流行之一,本篇我们就采用JQUERY来消费WCF RestFul服务,其中用到JSON基础知识,如果有想了解的朋友,请访问:& ...

  4. 使用多种客户端消费WCF RestFul服务(三)——.net4.5篇

    .net 4.5篇 在.net 4.5下面微软提供了System.Net.Http.dll可以非常方便的使用HTTP请求(其实是用来支持Asp.Net Web Api的,不过我们可以拿过来用) 服务仍 ...

  5. [经验] - JQuery.Ajax + 跨域 (crossDomain) + POST + JSON + WCF RESTful, 5大陷阱和解决方案

    最近在开发WSS RESTful服务的时候, 碰到了这些个纠结的问题. 在网上查找了半天, 找到n多种解决方案, 但是都是部分的, 要么是没有跨域的情况, 要么是没有post的情况, 要么不是用WCF ...

  6. WCF Restful Service的服务

    构建基于WCF Restful Service的服务 前言 传统的Asmx服务,由于遵循SOAP协议,所以返回内容以xml方式组织.并且客户端需要添加服务端引用才能使用(虽然看到网络上已经提供了这方面 ...

  7. JQuery.Ajax + 跨域 (crossDomain) + POST + JSON + WCF RESTful, 5大陷阱和解决方案

    JQuery.Ajax + 跨域 (crossDomain) + POST + JSON + WCF RESTful, 5大陷阱和解决方案 最近在开发WSS RESTful服务的时候, 碰到了这些个纠 ...

  8. WCF Restful Service Get / Post请求

    Rest 它是用于创建分布式超文本媒体的一种架构方式,我们可以通过标准的HTTP(GET,POST,PUT,DELETE)操作来构建基于面向资源的软件架构方式(Resource-Oriented Ar ...

  9. 大比速:remoting、WCF(http)、WCF(tcp)、WCF(RESTful)、asp.net core(RESTful)

    近来在考虑一个服务选型,dotnet提供了众多的远程服务形式.在只考虑dotnet到dotnet的情形下,我们可以选择remoting.WCF(http).WCF(tcp).WCF(RESTful). ...

随机推荐

  1. set 容器的用法

    1.set容器的理解 所有元素都会根据元素的键值自动排序,set元素的键值就是实值,实值就是键值.set不允许两个元素有相同的键值.(set的元素不像map那样可以同时拥有实值(value)和键值(k ...

  2. Android:如何生成自己的keystore(zz)

    keystore不设置的话默认使用的是C:\Users\Fly\.Android下面的debug.keystore,每台电脑的都不一样,所以导致了无法安装的情况. 如何生成自己的keystore呢?这 ...

  3. JSP展示两位小数

    <td class="thCenter"> <fmt:formatNumber type="number" value="${rec ...

  4. curl命令转换成php源码

    curl命令转换成php源码 获取状态: curl -X GET -H "Content-Type:application/json" -H "Authorization ...

  5. CTR预估算法之FM, FFM, DeepFM及实践

    https://blog.csdn.net/john_xyz/article/details/78933253 目录目录CTR预估综述Factorization Machines(FM)算法原理代码实 ...

  6. Eslint 规则说明

    "no-alert": 0,//禁止使用alert confirm prompt"no-array-constructor": 2,//禁止使用数组构造器&qu ...

  7. 最新的Delphi版本号对照

    The CompilerVersion constant identifies the internal version number of the Delphi compiler. It is de ...

  8. Eclipse SVN clean up失败解决方法

    错误信息: 1.下载sqlite3.zip  (https://www.sqlite.org/2019/sqlite-tools-win32-x86-3270200.zip) 只需用到解压后的exe文 ...

  9. Centos7.4别名设置提高工作效率

    一.打开 .bashrc文件 1.位置:~(cd ~)目录下 2.cat .bashrc 原文件内容如下: # .bashrc # User specific aliases and function ...

  10. 谈谈tmpdir与innodb_tmpdir的区别和用处

    [背景] innodb_tmpdir是在innodb online ddl中提到的一个参数:大致的意思是innodb在做online-ddl的时候会向临时目录写入“临时排序文件” 而这些文件的大小基本 ...