基本信息
源码名称:REST与SOA两种架构
源码大小:0.47M
文件格式:.rar
开发语言:C#
更新时间:2019-05-07
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 15 元 
   源码介绍

它基于HTTP协议,是一种明确构建在客户端/服务端体系结构上的一种风格。特征如下:
1、网络上的资源都被抽象为资源,这些资源都具有唯一的统一资源标识符
(URI:Uniform Resource Identiter),这些资源都是自我们描述的。这些资源使用HTTP内容标头类型指定。如:XML、JSON、HTML、PNG等。
2、服务的使用者通过HTTP协议的标准动作(Get、Put、Post、Delete)通过统一的接口对资源进行操作。
3、对资源进行的操作不会改变它的URI。
4、客户端、服务端之间的交互是没有状态的。由于这种无状态行,服务端不需要为每个客户端维护Context



using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.ServiceModel;
using SOAContracts;

namespace ClientConsole
{
	class Program
	{
		static void Main()
		{
			Console.WriteLine("调用SOA 服务....");
			InvoleSOAService();
			Console.WriteLine();
			Console.WriteLine("调用REST服务....");
			InvokeRESTService();
			Console.ReadLine();
		}

		static  void InvoleSOAService()
		{
			using (ChannelFactory<ILog> factory = new ChannelFactory<ILog>("SOAService"))
			{
                try
                {
                    ILog log = factory.CreateChannel();
                    List<LogEntity> listAll = log.GetAll();
                    Console.WriteLine(string.Format("SOA Service中 GetAll 方法获取到日志记录有{0}条", listAll.Count));
                    Console.WriteLine();
                    const string year = "2011";
                    const string month = "10";
                    List<LogEntity> list = log.GetMonthLog(year, month);
                    Console.WriteLine(string.Format("SOA Service中 GetMonthLog 方法获取到{0}年{1}月日志记录有{2}条", year, month, list.Count));
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();//让窗体保存接受外部参数的状态来达到不退出的效果
                }
			}			
		}

		static void InvokeRESTService()
		{
			HttpWebRequest request = WebRequest.Create("http://127.0.0.1:8866/RESTService.svc/") as HttpWebRequest;//http://127.0.0.1:8866/RESTService.svc/
            request.Method = "GET";
			HttpWebResponse response = request.GetResponse() as HttpWebResponse;
			using (StreamReader reader=new StreamReader(response.GetResponseStream()))
			{
				if (response.StatusCode==HttpStatusCode.OK)
				{
					Console.WriteLine(string.Format("REST Service 中GetAll 方法读取到的数据为:{0}", reader.ReadToEnd()));
				}
			}

		}

	}
}