在B/S开发中,涉及到获取系统基础资料的问题,因为是在不同平台下的开发,采用了WCF方式获取。
下面是一个调用通用权限管理系统(吉日嘎拉)基础信息资料的一个demo供参考
调用原理图:
web.configWCF配置参考
web.config 相关配置
<system.serviceModel>
<client>
<endpoint address="http://192.168.1.199/PermissionService.asmx"
binding="basicHttpBinding" bindingConfiguration="PermissionServiceSoap"
contract="WebPermission.PermissionServiceSoap" name="PermissionServiceSoap">
</endpoint>
<endpoint address="net.tcp://192.168.1.199:9999/DotNet.Business/BaseItemDetailsService/" behaviorConfiguration="Internet" binding="netTcpBinding" bindingConfiguration="netTcpBindingSmiple" contract="DotNet.Business.IBaseItemDetailsService" name="DotNet.Business.BaseItemDetailsService">
<identity>
<dns value="192.168.1.199" />
</identity>
</endpoint>
<endpoint address="net.tcp://192.168.1.199:9999/DotNet.Business/BaseItemsService/" behaviorConfiguration="Internet" binding="netTcpBinding" bindingConfiguration="netTcpBindingSmiple" contract="DotNet.Business.IBaseItemsService" name="DotNet.Business.BaseItemsService">
<identity>
<dns value="192.168.1.199" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="Internet">
</behavior>
</endpointBehaviors>
</behaviors>
<bindings> <basicHttpBinding>
<binding name="PermissionServiceSoap" />
<binding name="basicHttpBindingSmiple" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding> <netTcpBinding>
<binding name="netTcpBindingSmiple" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport clientCredentialType="Windows" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding> </bindings> </system.serviceModel>
注意:下面的userInfo是登录通用权限管理系统后的用户信息表,登录后需要设置对应的安全认证信息。
页面
/// <summary>
/// 基本信息表表名
/// </summary>
protected string itemName = string.Empty;
/// <summary>
/// 输出的json内容
/// </summary>
protected string jsonStr = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
itemName = string.IsNullOrWhiteSpace(RequestString("itemName")) || string.Equals(RequestString("itemName"), "null", StringComparison.OrdinalIgnoreCase) ? string.Empty : RequestString("itemName").Trim();
if (!string.IsNullOrWhiteSpace(itemName) && !string.IsNullOrWhiteSpace(itemName))
{
using (DataTable dt = ItemsManager.GetItemsDB(userInfo, "ItemsClass"))
{
//过滤 显示或不显示 DeletionStateCode为0的字段显示,Enabled为1的字段
BaseBusinessLogic.SetFilter(dt, BaseItemDetailsEntity.FieldDeletionStateCode, "0");
BaseBusinessLogic.SetFilter(dt, BaseItemDetailsEntity.FieldEnabled, "1");
DataTable dtNew = new DataTable();
dtNew.Columns.Add("key", typeof(string));
dtNew.Columns.Add("value", typeof(string));
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dtNew.NewRow();
row["key"] = dt.Rows[i]["ITEMNAME"];
row["value"] = dt.Rows[i]["ITEMVALUE"];
dtNew.Rows.Add(row);
}
jsonStr = DataTableHelper.DataTable2Json(dtNew);
}
}
else
{
jsonStr = "{\"list\":[{\"key\":\"出错了\",\"value\":\"取数据出错\",\"myFlag\":\"没有传入参数值\"}]}";
}
Response.Write(jsonStr);
Response.End();
}
业务层
using System.Collections.Generic;
using System.Data;
using System.Web;
namespace TransferFees.BLL
{
using System;
using System.Web.Caching;
using DotNet.Business;
using DotNet.Utilities;
using TransferFees.DAL;
using TransferFees.Foundation;
/// <summary>
/// 获取基础信息表资料业务类
/// 以安全的WCF方式访问
/// 1,增加缓存功能
///
/// <author>
/// <name>songbiao</name>
/// <date>2014.03.18</date>
/// </author>
/// </summary>
/// </summary>
/// </summary>
public class ItemsManager
{
/// <summary>
/// 获得基础信息表资料
/// 通过安全的WCF服务方式调用
/// 传入的用户实体含有配置的加密信息
/// </summary>
/// <param name="userInfo">用户实体</param>
/// <param name="itemName">要查询的基础信息表的表名</param>
/// <returns></returns>
public static DataTable GetItemsDB(BaseUserInfo userInfo, string itemName, bool refreshFlag = false)
{
string key = "GetItemsDB";
if (refreshFlag)
{
HttpContext.Current.Cache.Remove(key);
}
if (HttpContext.Current.Cache[key] == null)
{
lock (userInfo)
{
if (HttpContext.Current.Cache[key] == null)
{
DataTable dtRes = ItemsServices.GetItemsDB(userInfo, itemName);
CacheItemRemovedCallback onRemoveCallback = new CacheItemRemovedCallback(CacheHelper.CacheItemRemovedCallback);
HttpContext.Current.Cache.Add(key, dtRes, null, DateTime.Now.AddMinutes(30.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, onRemoveCallback);
}
}
}
return HttpContext.Current.Cache[key] as DataTable;
} /// <summary>
/// 获得基础信息表资料
/// 用户实体含有配置的加密信息
/// </summary>
/// <param name="userInfo">用户实体</param>
/// <param name="itemName">要查询的基础信息表的表名</param>
/// <returns></returns>
public static List<BaseItemDetailsEntity> GetItemsList(BaseUserInfo userInfo, string itemName, bool refreshFlag = false)
{
string key = "GetItemsList";
if (refreshFlag)
{
HttpContext.Current.Cache.Remove(key);
}
if (HttpContext.Current.Cache[key] == null)
{
lock (userInfo)
{
if (HttpContext.Current.Cache[key] == null)
{
List<BaseItemDetailsEntity> listRes = ItemsServices.GetItemsList(userInfo, itemName);
CacheItemRemovedCallback onRemoveCallback = new CacheItemRemovedCallback(CacheHelper.CacheItemRemovedCallback);
HttpContext.Current.Cache.Add(key, listRes, null, DateTime.Now.AddMinutes(30.0), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, onRemoveCallback);
}
}
}
return HttpContext.Current.Cache[key] as List<BaseItemDetailsEntity>;
}
}
}
数据访问层
using System.Collections.Generic;
using System.Data;
using DotNet.Business;
using DotNet.Utilities; namespace TransferFees.DAL
{
/// <summary>
/// 获取基础信息表资料服务类
/// 以安全的WCF方式访问
///
/// <author>
/// <name>songbiao</name>
/// <date>2014.03.18</date>
/// </author>
/// </summary>
/// </summary>
/// </summary>
public class ItemsServices
{
/// <summary>
/// 获得基础信息表资料
/// 通过安全的WCF服务方式调用
/// 用户实体含有配置的加密信息
/// </summary>
/// <param name="userInfo">用户实体</param>
/// <param name="itemName">要查询的基础信息表的表名</param>
/// <returns></returns>
public static DataTable GetItemsDB(BaseUserInfo userInfo,string itemName)
{
DotNetService dotNetService = new DotNetService("DotNet.WCFClient");
return dotNetService.BaseItemDetailsService.GetDataTable(userInfo, itemName);
}
/// <summary>
/// 获得基础信息表资料
/// 用户实体含有配置的加密信息
/// </summary>
/// <param name="userInfo">用户实体</param>
/// <param name="itemName">要查询的基础信息表的表名</param>
/// <returns></returns>
public static List<BaseItemDetailsEntity> GetItemsList(BaseUserInfo userInfo, string itemName)
{
DotNetService dotNetService = new DotNetService("DotNet.WCFClient");
return dotNetService.BaseItemDetailsService.GetList(userInfo, "ItemsClass");
}
}
}
这段时间一直在基于吉日嘎拉的通用权限管理系统上做开发,真心感觉他真的是很强大,
他真的不仅仅是一套权限管理系统,底层涉及到的安全问题考虑的也非常全面。
用上这套权限管理系统,我们只需关心业务就行了,时间对开发人员、对公司来说都非常重要,有一个好的选择我们一定要用上。
今后有机会会分享更多的应用,欢迎使用过这套系统的朋友一起交流。