為Dynamics365 web service建立訪問中轉伺服器
也許有人會問: Dynamics365的webservice已經支援RESTful和soap的訪問, 是否有必要再做一箇中轉伺服器?? 答案是肯定的, 因為:
1/ License問題, 每個授權使用者是要收錢的, 中轉伺服器使用一個account來訪問Dynamics 365服務, 節省開支
2/ 開發環境中, 登入Dynamics365需要連線微軟伺服器來認證, 這對於一些沒有外購訪問權的移動裝置客戶端的除錯就相當不友好了
3/中轉伺服器可以將認證憑證cache,加速資料訪問的速度
4/中轉伺服器只是做資料格式的轉換和中轉,所以對呼叫各種soap風格的api都是通用的, 無需改完Dynamics365的程式碼,又改這個中轉伺服器的程式碼
5/中轉伺服器的資料傳輸使用json格式,方便android app等移動裝置的除錯
由於soap才支援多公司切換,所以配置檔案application-live1.properties如下:
在配置檔案中指定d365服務的訪問方法為soap, 這個跳板能訪問到的d365 服務組(多個的話,用逗號分隔)為哪些,登入使用者、密碼,Client Id,公司名等
在後臺的Dynamics365建立一個AEL_RNote的servicegroup,在其下面加入AEL_RNote_Service服務, AEL_RNote_Service對應的class加入一組method:
public str getUnPostedNotes(str createby) { AEL_ReplacementNote_master master; container lvCnt; while select master order by AEL_rl_line,AEL_rl_no desc where master.AEL_rl_createuser==createby && master.AEL_rl_status!=AEL_rl_status::DS_Posted && (master.AEL_rl_type=="IR"||master.AEL_rl_type=="PS"||master.AEL_rl_type=="LR") { lvCnt+=master; } return this._getNotes(lvCnt); }
build一下這個project,然後用以下方式啟動d365訪問跳板:
..\jdk1.8\bin\java.exe -jar d365tunnel-0.0.1-SNAPSHOT.jar --spring.config.location=classpath:/application.properties,d:/temp/application-live1.properties --spring.profiles.active=live1
過一會,console會出現如下資訊, 最後它告訴你可以通過8081埠訪問這個跳板, 而通過這個跳板可以直接訪問Dynamics365的soap服務.
開啟chrome測試一下,輸入http://xxxxxx:8081/stdcall/AEL_RNote/AEL_RNote_Service/getUnPostedNotes?createby=testuser1
頁面上返回json結果:
{"errCode":0,"errMsg":"","errRef":"","result":[{"rejectBy":"dgmislrh","rejectDate":1539656456000,"rejectComment":"","apprInfo":[{"userId":"dgpd1zty","userName":"曾天宇","action":"Submit","level":1,"opTime":"15/Oct/2018 12:20:59"},{"userId":"dgpd1lyz","userName":"劉元治","action":"Approved","level":2,"opTime":"16/Oct/2018 10:18:21"},{"userId":"dgmislrh","userName":"李潤輝","action":"Rejected","level":3,"opTime":"16/Oct/2018 10:20:56"}],"line":"NB01","serverReplacementNoteId":"IR000036","status":0,"submitBy":"dgpd1zty","submitByName":"","submitDate":1539577258000,"type":"IR","updateBy":"","updateByName":"","updateDate":0,"remark":"","replacementNoteDetails":[{"binNumber":"","qpa":153.0,"qty":5.0,"reason":"引腳氧化","desc":"CHIP RESISTOR 100 ohm +-5% 1/16W (T&W) (0402/1005)","job":"JNB0000075","line":"NB01","ln":1,"finishTotal":0.0,"releasedQty":67.0,"jobRequired":153.0,"RecId":5637147983,"supplier":"SCN03","poNo":"","partNumber":"001-310156W016","totalReturnedValue":0.0}],"job":"JNB0000075","operNo":10,"modelNumber":"CN6114C451"}]}
github 下載地址: https://github.com/tiger822/d365connector