一、WebService
1.提供WebService服务
1)创建%SOAP.WebService派生类,添加NAMESPACE、SERVICENAME
2)参考web.DHCANService
2.调用WebService
1)创建%SOAP.WebClient的派生类,添加LOCATION、NAMESPACE、SERVICENAME
web.DHCCLDevSoapInferface
2)参考 web.DHCCLDevSoapInferface
3)添加验证
a.HIS8.3后需要添加验证
do obj.WSSecurityLogin("dhwebservice","dhwebservice")
b.HIS8.5的均需求添加SSL验证
注意: HIS8.5的均需求添加SSL验证! URL地址由web/webservice改为: imedical/webservice
s obj.Location="https://192.168.165.24:1443/imedical/webservice/web.DHCANService.cls"
set obj.SSLConfiguration="ANSSLConfiguration"
d obj.WSSecurityLogin("dhwebservice","dhwebservice")
注意:
调用时NAMESPACE双方需要一至
二、HTTP
1.HTTP服务端
1)获取GET、POST参数
%request会将get中的URL数据,表单数据转化为%request.Data数据,因此不必写代码分别处理
Write %request.Data("A",1)、
/// 前台调用时,根据方法或Query参数调用
/// 注: 当方法或Query的参数是JSON字符串时前台需要对传入JSON字符串,比如DHCBP.Register的Save方法
Class web.DHCCLMobileInferface Extends %CSP.Page
{
ClassMethod OnPreHTTP(ByRef OutputBody As %Boolean) As %Boolean
{
/*星号表示所有的域都可以接受,*/
Do %response.SetHeader("Access-Control-Allow-Origin","*")
Do %response.SetHeader("Access-Control-Allow-Methods","GET,POST")
Do %response.SetHeader("Access-Control-Allow-Headers","x-requested-with,content-type")
// Do %response.SetHeader("Access-Control-Allow-Headers","x-requested-with,content-type")
//Do %response.SetHeader("Content-Type","application/pdf")
Quit 1
}
ClassMethod OnPage() As %Status
{
try{
s msgType=%request.Data("MsgType",1)
s params=%request.Data("Params",1)
s clsName=%request.Data("ClassName",1)
2.HTTP客户端
1).通过%Net.HttpRequest类Post JSON数据并获取数HTTP数据
ClassMethod Post(startDate, startTime, endDate, endTime)
{
// s startDate="2018-08-16"
// s startTime="06:59:19"
// s endDate="2018-08-16"
// s endTime="07:01:14"
// w ##class(web.DHCANOPAttendance).Post(startDate, startTime, endDate, endTime)
s startDatetime=startDate_" "_startTime
s endDatetime=endDate_" "_endTime
Set httprequest=##class(%Net.HttpRequest).%New()
//set httprequest.SSLConfiguration="MySSLConfiguration"
set httprequest.SSLCheckServerIdentity=0 ;旧的库需要添加
set httprequest.Https=0
set httprequest.Server="192.9.230.90"
set httprequest.Port=8090
// httprequest.InsertFormData("Content-Type","text/plain")
d httprequest.ContentTypeSet("application/x-www-form-urlencoded; charset=UTF-8;text/plain")
d httprequest.Head("Accept-Encoding","gzip,deflate,sdch")
d httprequest.Head("Accept-Language","zh-CN,zh;q=0.8")
s httprequest.ContentCharset="UTF-8"
s semicolon=""""
set requestData="{"_semicolon_"starttime"_semicolon_":"_semicolon_startDatetime_semicolon_","
set requestData=requestData_semicolon_"endtime"_semicolon_":"_semicolon_endDatetime_semicolon_"}"
d httprequest.EntityBody.Write(requestData)
set tSc = httprequest.Post("/api/v2/transaction/get/?key=a702e2gxnd81gxruy_xigjb6pnwy5pmw5gn16thq1nor")
s strRes=""
do{
s res=httprequest.HttpResponse.Data.ReadLine()
s strRes=strRes_res
}
while(res'="")
s strRes=$ZCONVERT(strRes,"I","JSON")
quit strRes
Quit httprequest.HttpResponse
}
2). 表单提交
Set httprequest=##class(%Net.HttpRequest).%New()
set httprequest.SSLConfiguration="MySSLConfiguration"
set httprequest.Https=1
set httprequest.Server="myserver.com"
set httprequest.Port=443
Do httprequest.InsertFormData("portalid","2000000")
set tSc = httprequest.Post("/url-path/")
Quit httprequest.HttpResponse
三、HTTPS
使用HTTPS前需要在 系统 > 安全管理 > SSL/TLS 配置 添加客户端的凭据
Set httprequest=##class(%Net.HttpRequest).%New()
set httprequest.SSLConfiguration="MySSLConfiguration"
set httprequest.SSLCheckServerIdentity=0 ;旧的库需要添加
set httprequest.Https=1
set httprequest.Server="things.icoldchain.cn"
set httprequest.Port=443
Do httprequest.InsertFormData("code","1520437297405")
Do httprequest.InsertFormData("deviceSN","B7ZAU040")
set tSc = httprequest.Post("/output/getDeviceProperties")
s strRes=""
do{
s res=httprequest.HttpResponse.Data.ReadLine()
s strRes=strRes_res
}
while(res'="")
s strRes=$ZCONVERT(strRes,"I","JSON")
quit strRes
Quit httprequest.HttpResponse