Hessian服务端实现了IHttpHandle,

默认情况下是在Web.Config中的handles接点中注册,这样当有 很多实现时比较麻烦

这个时候可以实现IHttpHandleFactory注册到Web.Config中,在Factory中实现对具体服务的实例化,

另外也可以使用RouteTable方式,自己实现以个IRouteHandle,注册到RouteTable的Routes表中,

需要注意的是,RouteTable方式在asp.net管线的位置靠前,会屏蔽掉后面的IHttphandle方式.

另外注意在IIS 6中,需要在IIS中添加对.hessian的印射(取消确认文件存在选择),而在IIS7.0中需要在Web.Config的Web.Server配置节里注册HttpHandle或HttpHandleFactory-如果采用的不是RouteTable方式的话

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Collections.Concurrent;
using System.Reflection;
namespace PhoneAPI.Service
{
public class HessianRouteHandle : IRouteHandler
{
private Lazy<ConcurrentDictionary<String, Type>> _ServiceLazy = new Lazy<ConcurrentDictionary<string, Type>>(() => {
var dic = new ConcurrentDictionary<String, Type>(); var assembly = Assembly.Load("F.Studio.Prime.Hessian");
//接口类完全限定名将".I"替换成".Impl."
//F.Studio.Prime.Hessian.Impl.AccountService 转换后如下
//f-studio-prime-hessian-accountservice
foreach (var type in assembly.GetTypes().ToList())
{
if (type.FullName.IndexOf(".Impl.") > && type.FullName.EndsWith("Service"))
{
var key = type.FullName.Replace(".Impl.", ".").Replace(".", "-").ToLower();
dic[key] = type;
}
} return dic;
}, true);
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{ var service = requestContext.RouteData.Values["service"].ToString();
if (_ServiceLazy.Value.ContainsKey(service))
{
return Activator.CreateInstance(_ServiceLazy.Value[service]) as IHttpHandler;
}
return null;
}
}
}
  void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
RouteTable.Routes.Add(new Route("{service}.hessian", new HessianRouteHandle()));
}
       private T GetHessionProxy<T>()
where T : class
{ var url = ServerUrl + typeof(T).FullName.Replace(".I", ".").Replace(".", "-").ToLower() + ".hessian";
return factory.Create(typeof(T), url) as T; }

最新文章

  1. mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理
  2. gtest学习一:在vs2013中搭建gtest环境
  3. Lattice Diamond 的学习之新建工程
  4. sharepoint 中waiting screen dialog的使用方法(JSOM)
  5. 7.Android之评分条RatingBar和拖动条SeekBar学习
  6. InnoDB与MyISAM的区别
  7. 如何快速正确的安装 Ruby, Rails 运行环境
  8. AJAX基础_AJAX获取PHP数据
  9. .h(头文件) .lib(库文件) .dll(动态链接库文件) 之间的关系和作用的区分
  10. 爬虫入门 手写一个Java爬虫
  11. Spring的69个知识点
  12. javafx:JavaFX Scene Builder 2.0打开含有第三方jar包的fxml文件报错 Caused by: java.lang.ClassNotFoundException
  13. vs code安装
  14. 一、MyCat的搭建
  15. JDK8新增接口的默认方法与静态方法
  16. 图像数据增强 (Data Augmentation in Computer Vision)
  17. springMVC接受json并打开新页面
  18. Mybatis -- 批量更新 -- updateBatch
  19. 一步一步 Pwn RouterOS之ctf题练手
  20. iptables简单规则记录

热门文章

  1. datasnap 如何监控客户端的连接情况
  2. WinRAR命令行版本 rar.exe使用详解
  3. canal 监控数据库表 快速使用
  4. .Net 常用开发工具
  5. ubuntu 安装u盘恢复
  6. Python3 impyla 连接 hiveserver2
  7. Linux安装初始化
  8. Ibatis/Mybatis模糊查询
  9. Haskell语言学习笔记(26)Identity, IdentityT
  10. Oracle VM VirtualBox做好虚拟硬盘后,如何进一步修改虚拟硬盘的大小