首頁>技術>

webservice介面模式是多個系統間對接的一種常用模式。

Web Service技術, 能使得執行在不同機器上的不同應用無須藉助附加的、專門的第三方軟體或硬體, 就可相互交換資料或整合。依據Web Service規範實施的應用之間, 無論它們所使用的語言、 平臺或內部協議是什麼, 都可以相互交換資料。

簡單的說,WebService就是一種跨程式語言和跨作業系統平臺的遠端呼叫技術。

本介面內容是HIS方提供一個webservice介面,給自助機去呼叫。互動流程如下:

選定醫生後,自助機提示患者繳費,

繳費後,此時再呼叫HIS介面,HIS處理內部掛號邏輯,使得醫生工作站能看到自助機上掛的,處理完後,把處理成功的訊息告訴自助機,自助機提示繳費成功,並且列印憑條。

自助機使用的過程中,每一步都需要呼叫HIS的介面,如果不呼叫HIS介面,自助機完全不具備任何功能。

考慮到多種因素,本專案採用C#.Net來發布webservice服務。

步驟:

1.建立一個資料夾用來存放專案原始碼,如 D:\zzj_webservice

2.開啟visual studio

3.在檔案->新建->專案 彈出的對話方塊裡選擇對應的路徑和專案型別,參考圖片中的箭頭

建立成功後,vs的介面如下

在windows資源管理器中看到的檔案如下:

4.在wbsvc\wbsvc資料夾下,新建一個“core”資料夾,然後往裡面複製CommandInfo.cs、DbHelperOra.cs、DESEncrypt.cs、PubConstant.cs 這四個cs檔案,這是4個C#的類,

主要用來干連接oracle資料庫、加解密的活兒。還需要在wbsvc\wbsvc資料夾下,新建一個“dll”資料夾,把Oracle.ManagedDataAccess.dll檔案複製進去,這個dll檔案提供了連線oracle

資料庫的一些底層驅動。

5.在vs2015中加入這幾個類,並新增對此dll的引用

6.再建立一個webservice資料夾,把要釋出的服務放在這個裡面,程式碼看著整潔

7.在n_webservice.asmx的指令碼中貼入如下程式碼

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using core;using System.IO;using System.Text;using System.Data;using Oracle.ManagedDataAccess.Client;namespace wbsvc.webservice{    /// <summary>    /// n_webservice 的摘要說明    /// </summary>    [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 n_webservice : System.Web.Services.WebService    {        [WebMethod]        public string HelloWorld()        {            return "Hello World";        }        [WebMethod]        public string test(string as_instr)        {            string ls_ret;            object o = core.DbHelperOra.GetSingle("select sysdate from dual");            if (o != null)            {                ls_ret = "出參:" + as_instr + "    " + o.ToString();            }            else            {                ls_ret = "查資料庫出錯";            }            return ls_ret;        }        /// <summary>        /// 釋出給自助機的方法        /// </summary>        /// <param name="sSin"></param>        /// <returns></returns>        [WebMethod]        public string uf_zzytj_server_ylz(string sSin)        {            if (sSin == "test001")            {                sSin = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?><SstRequest><zdbh00>320300602107</zdbh00><yyjgdm>2</yyjgdm><funcid>H07.01.01.01</funcid><signature>9812630B3FD231357F39766AA67489B5</signature><RequestSet><YYRQ00>2020-12-14</YYRQ00><MZLXBH>1</MZLXBH></RequestSet></SstRequest>";            }            IDataParameter[] oracleParameter =            {                new OracleParameter(":sin", OracleDbType.Varchar2, 32767),                new OracleParameter(":sout",OracleDbType.Clob)            };            oracleParameter[0].Value = sSin; //引數1是入參 用value關鍵字            oracleParameter[1].Direction = ParameterDirection.Output; //引數2 是出參,用Direction關鍵字            string outputstr = string.Empty;            Write("", "入參:" + "\r\n" + "inputstr:  " + sSin);            string ls_proc_name = System.Configuration.ConfigurationManager.AppSettings["proc_name"].ToString();            core.DbHelperOra.RunProcedure(ls_proc_name, oracleParameter, (reader) =>            {                if (oracleParameter[1].Value != null)                {                    Oracle.ManagedDataAccess.Types.OracleClob outputjson = (Oracle.ManagedDataAccess.Types.OracleClob)oracleParameter[1].Value;                    outputstr = outputjson.Value;                }                else                {                    outputstr = "";                }            });            Write("", "出參:" + "\r\n" + "outputstr:  " + outputstr + "\r\n" + Environment.NewLine);            return outputstr;        }        /// <summary>        /// 寫日誌 2020-12-14         /// </summary>        /// <param name="fileName">檔案路徑+檔名</param>        /// <param name="sContent">日誌內容</param>        public static void Write(string fileName, string sContent)        {            try            {                string sPath = System.Configuration.ConfigurationManager.AppSettings["logpath"].ToString();                if (string.IsNullOrEmpty(sPath))                {                    sPath = HttpContext.Current.Server.MapPath("~/") + "/zzytj_log";                }                if (!Directory.Exists(sPath))                {                    Directory.CreateDirectory(sPath);                }                if (string.IsNullOrEmpty(fileName))                {                    fileName = DateTime.Now.ToString("yyyy-MM-dd");                }                string sTxt = sPath + "/" + fileName + ".txt";                File.AppendAllText(sTxt,                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +                                   string.Format(sContent) + Environment.NewLine,                                   Encoding.Default);            }            catch (Exception ex)            {                //File.AppendAllText("D://JybServiceLog.txt", $@"異常:{ex.Message}" + Environment.NewLine, Encoding.Default);            }        }    }}

把web.config的內容改成如下

9.下一步就可以釋出成檔案,準備複製到伺服器上釋出。

釋出後生成了如下檔案:

10.把上一步的釋出檔案,複製到伺服器上的C:\inetpub\zzj_dotnet

在iis中新建網站

OK

22
  • 2025 年 PS 設計必備!5 個設計師私藏的素材網站,從此告別版權煩惱
  • 微服務架構實戰:可擴充套件分散式資料庫叢集的搭建