(1)创建WCF
代码示例:
[ServiceContract]
public interface ILimsDBService
{
[OperationContract]
int ExecuteSql(string strSql); 
[OperationContract]
DataTable GetDataTable(string strSql); 
[OperationContract]
DataSet GetDataSet(string strSql);
}
public class LimsDBService : ILimsDBService
{
public int ExecuteSql(string strSql)
{
OracleDBHelper dbo = new OracleDBHelper(ConfigInfo.LimsDbConnStr);
return dbo.ExecuteSql(strSql);
public DataTable GetDataTable(string strSql)
{
OracleDBHelper dbo = new OracleDBHelper(ConfigInfo.LimsDbConnStr);
return dbo.GetDataTable(strSql);
public DataSet GetDataSet(string strSql)
{
OracleDBHelper dbo = new OracleDBHelper(ConfigInfo.LimsDbConnStr);
return dbo.GetDataSet(strSql);
}
}
(2)创建Windows服务
代码示例:
public partial class LimsHsSysService : ServiceBase
{
ServiceHost LimsDBServiceHost = new ServiceHost(typeof(LimsDBService));
public LimsHsSysService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
LimsDBServiceHost.Open();
}
protected override void OnStop()
{
LimsDBServiceHost.Close();
}
}
(3)配置客户端
功能代码:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress address = new EndpointAddress("http://192.168.4.179:8732/Design_Time_Addresses/WcfLimsServer/LimsDBService/");
LimsDBServiceClient lims = new LimsDBService.LimsDBServiceClient(binding, address);
string sql = "select sample_id,material_type from nais_all_samples where sample_id=" + this.txtQuery.Text.Trim();
DataTable dt = lims.GetDataSet(sql).Tables[0];
this.gvData.DataSource = dt;
this.gvData.DataBind();

基于Windows服务的WCF的更多相关文章

  1. WCF开发实战系列四:使用Windows服务发布WCF服务

    WCF开发实战系列四:使用Windows服务发布WCF服务 (原创:灰灰虫的家http://hi.baidu.com/grayworm) 上一篇文章中我们通过编写的控制台程序或WinForm程序来为本 ...

  2. asp.net基于windows服务实现定时发送邮件的方法

    本文实例讲述了asp.net基于windows服务实现定时发送邮件的方法.分享给大家供大家参考,具体如下: //定义组件 private System.Timers.Timer time; publi ...

  3. C#.NET 操作Windows服务承载WCF

    Windows服务的制作.安装可以参考这篇: C#.NET 操作Windows服务(安装.卸载) - runliuv - 博客园 (cnblogs.com) 本篇会在这个解决方案基础上,继续修改. 一 ...

  4. 编写寄宿于windows服务的WCF服务

    由于业务中有些任务需要在后台静默长期运行,或者有些服务队响应的要求比较苛刻,这样的WCF服务就不适合寄宿于IIS中.IIS每隔一段时间w3wp进程会闲置超时,造成服务的运行停止,因此这种耗时或者定时任 ...

  5. 基于Windows服务的聊天程序(一)

    本文将演示怎么通过C#开发部署一个Windows服务,该服务提供各客户端的信息通讯,适用于局域网.采用TCP协议,单一服务器连接模式为一对多:多台服务器的情况下,当客户端连接数超过预设值时可自动进行负 ...

  6. 基于Windows服务的聊天程序

    本文将演示怎么通过C#开发部署一个Windows服务,该服务提供各客户端的信息通讯,适用于局域网.采用TCP协议,单一服务器连接模式为一对多:多台服务器的情况下,当客户端连接数超过预设值时可自动进行负 ...

  7. Windows服务承载WCF

    Source文件 ------------------------- using System; using System.Collections.Generic; using System.Linq ...

  8. Topshelf + Quartz2.5 创建基于windows服务

    1.创建一个定时调度Quartz类 using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; u ...

  9. Quartz.NET Windows 服务示例

    想必大家在项目中处理简单的后台持续任务或者定时触发任务的时候均使用 Thread 或者 Task 来完成,但是项目中的这种需求一旦多了的话就得将任务调度引入进来了,那今天就简单的介绍一下 Quartz ...

随机推荐

  1. 一文带你超详细了解Cookie

    cookie 简介 什么是 cookie cookie,有时我们也用其复数形式 cookies,是服务端保存在浏览器端的数据片段.以 key/value的形式进行保存.每次请求的时候,请求头会自动包含 ...

  2. RK3399配置笔记

    1. adb shell 默认超级管理员 在build/core/main.mk下将ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1改成ADDITIONAL_D ...

  3. 从壹开始前后端 [vue后台] 之二 || 完美实现 JWT 滑动授权刷新

    缘起 哈喽大家周一好!不知道小伙伴们有没有学习呀,近来发现各种俱乐部搞起来了,啥时候群里小伙伴也搞一次分享会吧,好歹也是半千了(时间真快,还记得5个月前只有20多人),之前在上个公司,虽然也参与组织过 ...

  4. 【swoole】如果使用好定时器功能

    swoole中提供了一个定期器的用法 $server->tick(1000, function() use ($server, $fd) { $server->send($fd, &quo ...

  5. K3数据字典备查

    select distinct f.FNumber as 系统代码, f.FName AS 系统名称,  d.FTableName AS 表名,d.FDescription AS 表说明,a.[nam ...

  6. 使用 FFT 进行频谱分析

    下面的示例说明了如何使用 FFT 函数进行频谱分析.FFT 的一个常用场景是确定一个时域噪声信号的频率分量. 首先创建一些数据.假设是以 1000 Hz 的频率对数据进行的采样.首先为数据构造一条时间 ...

  7. 为什么腾讯有QQ,还要推出微信?

    在微信刚出现时候,很多人奇怪,为什么腾讯有QQ,还要推出微信? 一开始,我也认为它与QQ没有什么区别.有这种看法,是因为绝大多数时候,我都仅仅只使用即时聊天功能,微信上有的语音.视频.文字等等,这些在 ...

  8. REST API disable / enable service auto start by API

    how to disable service auto start by API as the following how to enable service auto start by API as ...

  9. 基于python语言的tensorflow的‘端到端’的字符型验证码识别源码整理(github源码分享)

    基于python语言的tensorflow的‘端到端’的字符型验证码识别 1   Abstract 验证码(CAPTCHA)的诞生本身是为了自动区分 自然人 和 机器人 的一套公开方法, 但是近几年的 ...

  10. ReactiveSwift源码解析(四) Signal中的静态属性静态方法以及面向协议扩展

    上篇博客我们聊了Signal的几种状态.Signal与Observer的关联方式以及Signal是如何向关联的Observer发送事件的.本篇博客继续上篇博客的内容,来聊一下Signal类中静态的ne ...