(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. [Active Learning] Multi-Criteria-based Active Learning

    目录 1 Informativeness 2 Representativeness 3 Diversity 3.1 Global consideration 3.2 Local considerati ...

  2. vue防止按钮在短时间内被多次点击的方法

    vue组件 (function(){ let openDelay=false; Vue.directive('intervalclick', function(el,binding){ el.oncl ...

  3. JAVA基础第二章-java三大特性:封装、继承、多态

    业内经常说的一句话是不要重复造轮子,但是有时候,只有自己造一个轮子了,才会深刻明白什么样的轮子适合山路,什么样的轮子适合平地! 我将会持续更新java基础知识,欢迎关注. 往期章节: JAVA基础第一 ...

  4. asp.net core系列 57 IS4 使用混合流(OIDC+OAuth2.0)添加API访问

    一.概述 在上篇中,探讨了交互式用户身份验证,使用的是OIDC协议. 在之前篇中对API访问使用的是OAuth2.0协议.这篇把这两个部分放在一起,OpenID Connect和OAuth 2.0组合 ...

  5. Solr 17 - Solr的时间为什么比本地少8小时 (附修改方法)

    目录 1 为什么少8小时 2 如何查看Solr的时区 3 修改Solr的时区 3.1 Solr从数据库中同步数据的原理 3.2 为什么要修改时区 3.3 如何修改时区 1 为什么少8小时 (1) 原因 ...

  6. @Controller和@RestController源码解析

    2018年不知不觉已经走到了尾声,你还在为分不清@Controller和@Restcontroller而烦恼吗?这篇博文从源码层面分析这两个注解,值得一读. 首先贴一张源码的图,对比一下,左边是@Co ...

  7. 第四节 pandas 数据加载

    pandas提供了一些用于将表格型数据读取为DataFrame对象的函数,其中read_csv和read_table这两个使用最多. #导包import pandas as pd from panda ...

  8. DSAPI显示PNG异形窗体

    使用DSAPI实现PNG异形窗体,注意,该窗体为层样式窗体,以PNG或32位带透明通道的图像合成到屏幕,此方法不会触发窗体的重绘,故原窗体(包括其子控件)均不会显示,如果需要更新画面,需要重新用代码等 ...

  9. c# 事件的订阅发布Demo

    delegate void del(); class MyClass1 { public event del eventcount;//创建事件并发布 public void Count() { ; ...

  10. Python中使用枚举类

    开发中我们经常定义常量, 其实有更好的方法:为这样的枚举类型定义一个class类型,然后,每个常量都是class的一个唯一实例.Python中提供了Enum类来实现这个功能: from enum im ...