.NET CORE 建立webservice以及.NET CORE呼叫webservice
阿新 • • 發佈:2022-03-28
一、服務端新增引用,SoapCore,版本是:1.1.0.10
二、建立DTO類
[DataContract] public class CallRequest { /* 介面規範為 (ip不為空的情況): {"YSYHID":"26036","YSXM":"曾禮特","PBID":"794961","BRBH":"00015501296380","ZKID":"42","FJID":"89","FJMC":"2號診室","FZYYID":"1260503", "CHBZ":"0","JZRQ":"","ZSPIP":"192.168.1.100"} (ip為空的情況): {"YSYHID":"26036","YSXM":"曾禮特","PBID":"794961","BRBH":"00015501296380","ZKID":"42","FJID":"89","FJMC":"2號診室","FZYYID":"1260503","CHBZ":"0","JZRQ":"","ZSPIP":""}*/ /// <summary> /// 呼叫醫生ID /// </summary> [DataMember] public string YSYHID { get; set; } /// <summary> /// 醫生姓名 /// </summary> [DataMember] public string YSXM { get; set; } /// <summary> /// 排班id/// </summary> [DataMember] public string PBID { get; set; } /// <summary> /// 病人編號 /// </summary> [DataMember] public string BRBH { get; set; } /// <summary> /// 科室程式碼 /// </summary> [DataMember]public string ZKID { get; set; } /// <summary> /// 房間ID /// </summary> [DataMember] public string FJID { get; set; } /// <summary> /// 房間名稱 /// </summary> [DataMember] public string FJMC { get; set; } /// <summary> /// 分診預約ID /// </summary> [DataMember] public string FZYYID { get; set; } /// <summary> /// 重呼標記 /// </summary> [DataMember] public string CHBZ { get; set; } /// <summary> /// 就診日期 /// </summary> [DataMember] public string JZRQ { get; set; } /// <summary> /// 診室屏IP /// </summary> [DataMember] public string ZSPIP { get; set; } }
三、服務端建立介面,用於暴露,
[ServiceContract] public interface ICallRequestService { [OperationContract] CallRequest Call(CallRequest s); }
四、建立實現類,
public class CallRequestService : ICallRequestService { public CallRequest Call(CallRequest s) { return new CallRequest() { BRBH ="9999999999999" }; } }
五、注入服務
services.TryAddSingleton<ICallRequestService, CallRequestService>();
六、服務端新增中介軟體
var binging = new BasicHttpBinding(); binging.ReaderQuotas.MaxStringContentLength = int.MaxValue; app.UseSoapEndpoint<ICallRequestService>("/CallRequestService.asmx", binging, SoapSerializer.XmlSerializer);
七、建立客戶端,使用mvc框架
八、新增webservice引用,一定要聯網,不然無法配置,發現服務,新增服務
九、呼叫服務,並且返回結果
public async void OnGet() { ServiceReference1.CallRequestServiceClient callRequestServiceClient = new ServiceReference1.CallRequestServiceClient(); ServiceReference1.CallRequest callRequest = new ServiceReference1.CallRequest() { BRBH = "666666" }; var r =await callRequestServiceClient.CallAsync(callRequest); int a = 0; }