private IRestResponse ExecutePost(string URI, VixServiceTypes serviceType, string requestInput) { RestRequest request = new RestRequest(URI, Method.POST); request.AddHeader("Accept", "text/plain,application/xml"); request.AddParameter("context", UserContext.ApplicationContext, ParameterType.UrlSegment); request.AddParameter("application/xml", requestInput, ParameterType.RequestBody); string transactionId = "{" + Guid.NewGuid().ToString() + "}"; RestClient client = GetRestClient(transactionId, serviceType); Log.Debug("Executing VIX POST. Transaction ID: " + transactionId + "..."); IRestResponse response = client.Execute(request); return response; }
private string GetBaseURL(VixServiceTypes serviceType) { Log.Debug("Retrieving base URLs for " + serviceType.ToString() + " service..."); string ServiceType; string BaseUrl = string.Empty; // change facace based on type switch (serviceType) { case VixServiceTypes.Pathology: ServiceType = "Pathology"; break; case VixServiceTypes.Patient: ServiceType = "Patient"; break; case VixServiceTypes.User: ServiceType = "User"; break; default: ServiceType = "Pathology"; break; } string IDSUrl = string.Format(SecureIDSQueryFormatString, this.VixServerName, this.VixServerPort, ServiceType); // getting the application path HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(IDSUrl); webRequest.Credentials = new NetworkCredential(VixUserName, VixPassword); HttpWebResponse response; try { response = (HttpWebResponse)webRequest.GetResponse(); } catch (Exception ex) { Log.Error("IDS: " + IDSUrl, ex); throw new MagVixFailureException("Cannot request IDS URL", ex); } // getting the application and operation path string VixApplicationPath = string.Empty; string VixOperationPath = string.Empty; using (Stream webStream = response.GetResponseStream()) using (XmlTextReader xmlReader = new XmlTextReader(webStream)) using (StreamReader webReader = new StreamReader(webStream)) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(xmlReader); string nodeAppPath = string.Format(VixApplicationPathQueryString, ServiceType); string nodeOperationPath = string.Format(VixMetadataOperationPathQueryString, ServiceType); VixApplicationPath = xmlDoc.SelectSingleNode(nodeAppPath).InnerText; VixOperationPath = xmlDoc.SelectSingleNode(nodeOperationPath).InnerText; } catch (Exception ex) { Log.Error("Failed to get app/op path.", ex); throw new MagVixFailureException("Failed to retrieve application and operation path", ex); } } // get the base url BaseUrl = string.Format(SecureBaseUrlFormatString, this.VixServerName, this.VixServerPort, VixApplicationPath, VixOperationPath); return BaseUrl; }
public RestClient GetRestClient(string transactionId, VixServiceTypes serviceType) { RestClient client = new RestClient(); switch (serviceType) { case VixServiceTypes.Pathology: client.BaseUrl = this.VixBasePathologyUrl; break; case VixServiceTypes.Patient: client.BaseUrl = this.VixBasePatientUrl; break; case VixServiceTypes.User: client.BaseUrl = this.VixBaseUserUrl; break; default : client.BaseUrl = this.VixBasePathologyUrl; break; } client.Authenticator = new HttpBasicAuthenticator(VixUserName, VixPassword); client.AddDefaultHeader("xxx-duz", UserContext.UserCredentials.Duz); client.AddDefaultHeader("xxx-fullname", UserContext.UserCredentials.Fullname); client.AddDefaultHeader("xxx-sitename", UserContext.UserCredentials.SiteName); client.AddDefaultHeader("xxx-sitenumber", UserContext.LocalSite.PrimarySiteStationNUmber); client.AddDefaultHeader("xxx-ssn", UserContext.UserCredentials.Ssn); client.AddDefaultHeader("xxx-option-context", "MAGTP_WORKLIST_MGR"); client.AddDefaultHeader("xxx-transaction-id", transactionId); client.AddDefaultHeader("xxx-securityToken", UserContext.UserCredentials.SecurityToken); client.AddDefaultHeader("xxx-client-version", FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion); return client; }