/// <summary> /// api/GetCompanyStatus?partyname=Morgan&city=Burbank&state=CA /// </summary> /// <param name="partyName">Morgan</param> /// <param name="city">Burbank</param> /// <param name="state">CA</param> /// <returns></returns> public List<PartySearchResult> GetParties(string partyName, string city, string state) { //build request HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Constants.APIURL_Prodect); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/xml"; httpWebRequest.Headers.Add("usmdm-action", "SB4C"); httpWebRequest.Headers.Add("APIkey", Constants.APIkey_Product); httpWebRequest.Headers.Add("APIKeySecret", Constants.APIKeySecret_Product); //pass data Instrument inStrument = new Instrument(); string sbParam = string.Format(DATA, inStrument.HandleSpecialCharacters(partyName), inStrument.HandleSpecialCharacters(city), inStrument.HandleSpecialCharacters(state)); byte[] formData = UTF8Encoding.UTF8.GetBytes(sbParam); httpWebRequest.ContentLength = formData.Length; using (Stream postStream = httpWebRequest.GetRequestStream()) { postStream.Write(formData, 0, formData.Length); } //get response string response = string.Empty; try { WebResponse webResponse = httpWebRequest.GetResponse(); using (Stream webStream = webResponse.GetResponseStream()) { if (webStream != null) { using (StreamReader responseReader = new StreamReader(webStream)) { response = responseReader.ReadToEnd(); } } } } catch (Exception) { //To do log the exception } XDocument xDoc = XDocument.Parse(response); return ReadXML(xDoc); //var XMLLoadfullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLFile_Hardcode_Source.xml"); //XDocument xdoc = XDocument.Load(XMLLoadfullPath); //List<PartySearchResult> Parties = ReadXML(xdoc); //string output = new JavaScriptSerializer().Serialize(Parties); //return output; }
/// <summary> /// sample: /// partyId = 5fed522f-4f34-4db6-8385-5802ea6e219d /// sourcePartyId = b1fd3502-3b31-465a-a0b8-cd844bd7004a /// string sbParam = "<getPartyDetailRequest><sourcePartyId>sourcePartyId</sourcePartyId></getPartyDetailRequest>"; /// string url = "http://10.22.53.151:9080/USMDMV2/REST/party?" + sbParam; /// </summary> /// <param name="sourcePartyId"></param> /// <returns></returns> public object GetPartyDetails(string sourcePartyId) { //input param check if (string.IsNullOrEmpty(sourcePartyId)) { return null; } //params defines string responeContent = string.Empty; string serviceURL = string.Empty; serviceURL = Constants.APIURL_Prodect; StringBuilder sbParam = new StringBuilder(); Instrument inStrument = new Instrument(); PartyDetailSearchResult partyResult = new PartyDetailSearchResult(); //Get URL sourcePartyId = inStrument.HandleSpecialCharacters(sourcePartyId); sbParam = GetParams(sourcePartyId); serviceURL = serviceURL + "?" + sbParam.ToString(); //Init http request HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(serviceURL); httpWebRequest.ContentType = "application/xml"; httpWebRequest.Method = "POST"; httpWebRequest.Headers.Add("usmdm-action", "GET"); httpWebRequest.Headers.Add("APIkey", Constants.APIkey_Product); httpWebRequest.Headers.Add("APIKeySecret", Constants.APIKeySecret_Product); //send http request byte[] bStream = System.Text.Encoding.Default.GetBytes(sbParam.ToString()); httpWebRequest.ContentLength = bStream.Length; using (Stream stream = httpWebRequest.GetRequestStream()) { stream.Write(bStream, 0, bStream.Length); } try { //Get http response HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), UTF8Encoding.UTF8); responeContent = streamReader.ReadToEnd(); httpWebResponse.Close(); streamReader.Close(); if (responeContent.Trim().Length <= 0) { return null; } //rebuild the returned xml data XmlDocument xmlDoc = inStrument.GetXmlDocByXmlContent(responeContent); string[] paramArray = { }; string statusValue = inStrument.GetNodeValue(xmlDoc, "overallStatus", paramArray); string statusDesc = inStrument.GetNodeValue(xmlDoc, "statusMessageDescription", paramArray); XDocument xdoc = XDocument.Parse(responeContent); if (statusValue.Equals("Success")) { partyResult = GetPartyFromXML(xdoc); //res = new JavaScriptSerializer().Serialize(GetPartyFromXML(xdoc)); } else { partyResult.IndependenceStatus = statusDesc; partyResult.IndependenceStatusCode = "-1"; } } catch (Exception ex) { partyResult.IndependenceStatusCode = "-1"; partyResult.IndependenceStatus = ex.Message; } return partyResult; }