使用RpcLite構建SOA/Web服務(Full .Net Framework)
SOA框架系列
1. 使用RpcLite構建SOA/Web服務
2. 使用RpcLite構建SOA/Web服務(Full .Net Framework)
繼前一篇文章《使用RpcLite構建SOA/Web服務》已過去好幾個月。在這幾個月裡對RpcLite作了很多修改如:.Net Core的支持、Fluent API方式配置、Monitor、Filter等功能。
前一篇文章介紹了使用RpcLite的基本用法,在文章中介紹的配置方式為配置文件使用起來比較麻煩。本文配置使用Fluent API方式,在.Net Core中可以完全不使用配置文件,在Asp.Net中僅需要添加一個HttpModule。
Full .Net Framework中現只支持Host到ASP.NET中。
創建服務包括以下步驟:
添加引用有兩種方式:直接下載dll然後引用、通過NuGet添加,其中通過NuGet添加簡單方便,本文以此方式為例。 通過NuGet添加也有兩種方式:圖形界面或命令行
命令行
圖形界面
在configuration/system.webServer節點下添加 <add name=”RpcLite” type=”RpcLite.Service.RpcHttpModule, RpcLite.NetFx” />
完整配置如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<add name="RpcLite" type="RpcLite.Service.RpcHttpModule, RpcLite.NetFx" />
</modules>
</system.webServer>
</configuration>
namespace HelloRpcLiteService
{
public interface IProductService
{
string GetDateTimeString();
}
}
using System;
namespace HelloRpcLiteService
{
public class ProductService : IProductService
{
public string GetDateTimeString()
{
return DateTime.Now.ToString();
}
}
}
using System;
using RpcLite.Config;
namespace HelloRpcLiteService
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RpcInitializer.Initialize(builder => builder
.UseService<ProductService>("ProductService", "api/service/")
.UseServicePaths("api/")
);
}
}
}
說明
Service Name: ProductService Actions: String GetDateTimeString();
通過RpcLite客戶端、JavaScript就可以訪問這個服務了。
本文代碼地址 https://github.com/aolyn/rpclite.docs/tree/master/samples/HelloRpcLite/src/HelloRpcLiteService
QQ群:364617712
歡迎加入
聯系方式