其实。。。很简单,为了省事,这里以Ado.NET为例(其实就是把你操纵数据库的哪些方法搬到WebMethoh里)
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class EmrService : System.Web.Services.WebService { public static System.Data.DataTable PatientData(string patientID) { var dt = new System.Data.DataTable(); try { var conString = System.Configuration.ConfigurationManager.ConnectionStrings["docare"].ConnectionString; var ad = new System.Data.OracleClient.OracleDataAdapter(string.Format(System.Configuration.ConfigurationManager.AppSettings["GetPatientInfoSql"],patientID), conString); ad.Fill(dt); } catch { return dt; } return dt; }
然后再配置sql语句即可
<appSettings> <add key="HemoRecord-EMRTYPE" value="血液透析记录" /> <add key="GetPatientInfoSql" value="SELECT T.PATIENT_ID PATIENTID,T.NAME PATIENTNAME,T.SEX PATIENTSEX,T.BIRTHDAY BIRTHDAY,T.AGE AGE FROM MED_PATIENTS T WHERE T.PATIENT_ID='{0}'" /> </appSettings>