(1) Create a WCF code example: [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 to dbo. ExecuteSQL (strSQL);} public DataTable getdatatable (string strsql) {oracledbhelper dbo = new Oracledbhelper (CONFIGINFO.LIMSDBCONNSTR); Return to dbo. Getdatatable (strSQL);} public DataSet GetDataSet (string strsql) {oracledbhelper dbo = new Oracledbhelper (CONFIGINFO.LIMSDBCONNSTR); Return to dbo. GetDataSet (strSQL);}} (2) Example of creating a Windows Service Code: Public partial class Limshssysservice:servicebase{servicehost limsdbservicehost = new ServiceHost ( typeof (Limsdbservice));p ublic Limshssysservice () {InitializeComponent ();} protected override void OnStart (string[] args) {Limsdbservicehost.open ();} protected override void OnstoP () {limsdbservicehost.close ();}} (3) Configuring the Client function code: 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 ();D atatable dt = LIMs. GetDataSet (SQL). Tables[0];this.gvdata.datasource = Dt;this.gvdata.databind ();
Windows Service-based WCF