zoukankan      html  css  js  c++  java
  • 基于Windows服务的WCF

    (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();

  • 相关阅读:
    luogu_1168: 中位数
    luogu_4762: [CERC2014]Virus synthesis
    luogu_4287:双倍回文
    回文自动机学习笔记
    luogu_3645: 雅加达的摩天楼
    python爬今日头条(ajax分析)
    Python多进程multiprocessing.Pool()
    Python爬微博(ajax+mongo)
    python实用函数之join()
    python之tuple与list
  • 原文地址:https://www.cnblogs.com/liusuqi/p/7992041.html
Copyright © 2011-2022 走看看