public GetContactByUserIdDataResponse GetContactByUserId(string userId) { Uri getContactUri = new Uri(string.Format("{0}/Contact/{1}/{2}/{3}/Contact/User/{4}?UserId={5}", Url, Context, Version, ContractNumber, userId, HeaderUserId)); HttpClient getContactClient = GetHttpClient(getContactUri); GetContactByUserIdDataRequest getContactRequest = new GetContactByUserIdDataRequest { SQLUserId = userId, Context = Context, Version = Version, ContractNumber = ContractNumber }; DataContractJsonSerializer getContactJsonSer = new DataContractJsonSerializer(typeof(GetContactByUserIdDataRequest)); MemoryStream getContactMs = new MemoryStream(); getContactJsonSer.WriteObject(getContactMs, getContactRequest); getContactMs.Position = 0; //use a Stream reader to construct the StringContent (Json) StreamReader getContactSr = new StreamReader(getContactMs); StringContent getContactContent = new StringContent(getContactSr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json"); getContactMs.Dispose(); //Post the data var getContactResponse = getContactClient.GetStringAsync(getContactUri); var getContactResponseContent = getContactResponse.Result; string getContactResponseString = getContactResponseContent; GetContactByUserIdDataResponse responseContact = null; using (var getContactMsResponse = new MemoryStream(Encoding.Unicode.GetBytes(getContactResponseString))) { var getContactSerializer = new DataContractJsonSerializer(typeof(GetContactByUserIdDataResponse)); responseContact = (GetContactByUserIdDataResponse)getContactSerializer.ReadObject(getContactMsResponse); } return(responseContact); }
private ObjectId GetUserId(string contractNumber, string productContext, string sqlUserID) { ObjectId returnId = ObjectId.Empty; GetContactByUserIdDataResponse contactDataResponse = null; IRestClient client = new JsonServiceClient(); string url = Common.Helper.BuildURL(string.Format("{0}/{1}/1.0/{2}/Contact/User/{3}", DDContactServiceUrl, productContext, contractNumber, sqlUserID), returnId.ToString()); contactDataResponse = client.Get <GetContactByUserIdDataResponse>(url); if (contactDataResponse != null && contactDataResponse.Contact != null) { returnId = ObjectId.Parse(contactDataResponse.Contact.Id); } return(returnId); }
public GetContactByUserIdDataResponse Get(GetContactByUserIdDataRequest request) { GetContactByUserIdDataResponse response = new GetContactByUserIdDataResponse(); response.Version = request.Version; try { if (string.IsNullOrEmpty(request.UserId)) { throw new UnauthorizedAccessException("ContactDD:Get()::Unauthorized Access"); } response.Contact = Manager.GetContactByUserId(request); } catch (Exception ex) { CommonFormat.FormatExceptionResponse(response, base.Response, ex); string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0"; Helpers.LogException(int.Parse(aseProcessID), ex); } return(response); }