public MatchingDetails GetMatchingDetails(string lastname, string postCode, string PHONE1, string PHONE2, string UEMAILADDR) { MatchingDetails matchingDetails = new MatchingDetails(); string jsonResult = string.Empty; GetMatchingDetailsSO getMatchingDetailsSO = new GetMatchingDetailsSO(); GoldmineImportServiceDO goldmineImportServiceDO = new GoldmineImportServiceDO(); string getMatchingDetailsSOAsJson = string.Empty; // set getMatchingDetailSO Properties getMatchingDetailsSO = PropertyAddition.SetGetMatchingDetailsSOProperties(lastname, postCode, PHONE1, PHONE2, UEMAILADDR, getMatchingDetailsSO); // Create URL and WebRequest Object string URL = string.Format("{0}GetMatchingDetails", goldmineImportServiceAddress); WebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL); httpWebRequest = ConnectorHelper.SetUpWebRequestObject(httpWebRequest); getMatchingDetailsSOAsJson = SerializationHelper.SerializeGetMatchingDetailsSO(getMatchingDetailsSO); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { // send request to service try { streamWriter.Write(getMatchingDetailsSOAsJson); streamWriter.Flush(); streamWriter.Close(); } catch (Exception ex) { ClientLogger.WriteError(ex, "Error retrieving the matching details.\nMethod: GoldmineImportServiceConnector.GetMatchingDetails", ClientGlobalData.CurrentUser.SystemName); throw ex; } // get response object HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { jsonResult = streamReader.ReadToEnd(); jsonResult = ConnectorHelper.ChangeArrayParentheses(jsonResult); } // deserialize try { goldmineImportServiceDO = JsonConvert.DeserializeObject <GoldmineImportServiceDO>(jsonResult); matchingDetails = goldmineImportServiceDO.GetMatchingDetailsResult; } catch (Exception ex) { ClientLogger.WriteError(ex, "Error deserializing the matching details.\nMethod: GoldmineImportServiceConnector.GetMatchingDetails", ClientGlobalData.CurrentUser.SystemName); HandleDeserializationException(ex); } } return(matchingDetails); }
public static string SerializeGetMatchingDetailsSO(GetMatchingDetailsSO obj) { try { MemoryStream stream = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GetMatchingDetailsSO)); ser.WriteObject(stream, obj); string serializedObject = Encoding.UTF8.GetString(stream.ToArray()); return(serializedObject); } catch (Exception ex) { throw ex; } }
public static GetMatchingDetailsSO SetGetMatchingDetailsSOProperties(string lastname, string postCode, string PHONE1, string PHONE2, string UEMAILADDR, GetMatchingDetailsSO getMatchingDetailsSO) { getMatchingDetailsSO.lastname = lastname; getMatchingDetailsSO.postCode = postCode; getMatchingDetailsSO.PHONE1 = PHONE1; getMatchingDetailsSO.PHONE2 = PHONE2; getMatchingDetailsSO.UEMAILADDR = UEMAILADDR; return(getMatchingDetailsSO); }