Produced by Araxis Merge on 5/20/2019 8:52:25 AM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | PPMS_Build_11_Sprint_3.zip\CIF B11S3\VA.PPMS.Plugins\VA.PPMS.Plugins\VA.PPMS.CRM.Plugins\Helper | AddressValidationHelper.cs | Wed Apr 17 20:05:02 2019 UTC |
| 2 | PPMS_Build_11_Sprint_3.zip\CIF B11S3\VA.PPMS.Plugins\VA.PPMS.Plugins\VA.PPMS.CRM.Plugins\Helper | AddressValidationHelper.cs | Thu May 16 16:27:56 2019 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 8 | 1124 |
| Changed | 7 | 18 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | using Syst em; | |
| 2 | using Syst em.Collect ions.Gener ic; | |
| 3 | using Syst em.IO; | |
| 4 | using Syst em.Net; | |
| 5 | using Syst em.Net.Htt p; | |
| 6 | using Syst em.Net.Htt p.Headers; | |
| 7 | using Syst em.Web; | |
| 8 | using Syst em.Runtime .Serializa tion.Json; | |
| 9 | using Syst em.Text.Re gularExpre ssions; | |
| 10 | using Syst em.Securit y.Cryptogr aphy.X509C ertificate s; | |
| 11 | using Syst em.Text; | |
| 12 | using Micr osoft.Xrm. Sdk; | |
| 13 | using VA.P PMS.Contex t; | |
| 14 | using Syst em.Linq; | |
| 15 | ||
| 16 | namespace VA.PPMS.CR M.Plugins. Helper | |
| 17 | { | |
| 18 | ||
| 19 | public static cl ass Addres sValidatio nHelper | |
| 20 | { | |
| 21 | pu blic stati c ITracing Service tr acingServi ce; | |
| 22 | ||
| 23 | pu blic stati c RootObje ctResponse ValidateW cIWS(Entit y careSite , string s treetAddre ss, string city, str ing state, string zi p, ITracin gService _ tracingSer vice, Ppms Context sv c, IOrgani zationServ ice _servi ce) | |
| 24 | { | |
| 25 | ||
| 26 | tracingS ervice = _ tracingSer vice; | |
| 27 | // Get o rganizatio n service reference | |
| 28 | tracingS ervice.Tra ce("Beginn ing Addres s Validati on"); | |
| 29 | tracingS ervice.Tra ce("Addres s Attribut es for Req uest:" + s treetAddre ss + ", " + city + " , " + stat e + ", " + zip); | |
| 30 | ||
| 31 | var addr essValidat ionResult = new Root ObjectResp onse(); | |
| 32 | //with c ert | |
| 33 | //using (MyClient wc = new M yClient()) | |
| 34 | using (W ebClient w c = new We bClient()) | |
| 35 | { | |
| 36 | //string p roxyAddres sString = "https:// DNS . URL /ase/Valid ateAddress /v1?street Address="; | |
| 37 | ||
| 38 | //Re trieve Add ress Valid ation URL from Setti ngs Entity | |
| 39 | stri ng proxyAd dressStrin g = ""; | |
| 40 | var settings = svc.ppms_ integratio nsettingsS et.FirstOr Default(i => i.Id != null); | |
| 41 | if ( settings = = null) { tracingSer vice.Trace ("Unable t o locate C RM Setting s entity") ; return n ull; } | |
| 42 | if ( settings.p pms_Addres sValidatio nEndpoint == String. Empty || s ettings.pp ms_Address Validation Endpoint = = null) { tracingSer vice.Trace ("Unable t o locate A ddress Val idation En dpoint URL on Integr ation Sett ings Recor d"); retur n null; } | |
| 43 | else | |
| 44 | { | |
| 45 | tracingSer vice.Trace ("Address Validation URL Locat ed on CRM Settings e ntity"); | |
| 46 | proxyAddre ssString = settings. ppms_Addre ssValidati onEndpoint ; | |
| 47 | } | |
| 48 | ||
| 49 | prox yAddressSt ring += "' " + street Address + "'"; | |
| 50 | prox yAddressSt ring += "& city="; | |
| 51 | prox yAddressSt ring += ci ty; | |
| 52 | prox yAddressSt ring += "& state="; | |
| 53 | prox yAddressSt ring += st ate; | |
| 54 | prox yAddressSt ring += "& zip="; | |
| 55 | prox yAddressSt ring += zi p; | |
| 56 | prox yAddressSt ring = Uri .EscapeUri String(pro xyAddressS tring).Rep lace("#", "%23"); | |
| 57 | ||
| 58 | trac ingService .Trace("Ad dress Stri ng: " + pr oxyAddress String); | |
| 59 | ||
| 60 | wc.H eaders[Htt pRequestHe ader.Conte ntType] = "applicati on/json"; | |
| 61 | ||
| 62 | ||
| 63 | trac ingService .Trace("Ma king Call to IWS Add ress Valid ation Func tion"); | |
| 64 | stri ng iwsResp onse = wc. DownloadSt ring(proxy AddressStr ing); | |
| 65 | ||
| 66 | if ( !string.Is NullOrEmpt y(iwsRespo nse)) | |
| 67 | { | |
| 68 | addressVal idationRes ult = Dese rialize<Ro otObjectRe sponse>(iw sResponse) ; | |
| 69 | if (addres sValidatio nResult != null) | |
| 70 | { | |
| 71 | tracin gService.T race("Suce ssful Resp onse from Address Va lidation A PI"); | |
| 72 | tracin gService.T race("Conf idence Sco re:" + add ressValida tionResult .addressMe taData.con fidenceSco re); | |
| 73 | } | |
| 74 | else | |
| 75 | { | |
| 76 | tracin gService.T race("Unsu ccessful R esponse fr om Address Validaton API"); | |
| 77 | return null; | |
| 78 | } | |
| 79 | return add ressValida tionResult ; | |
| 80 | } | |
| 81 | else | |
| 82 | { | |
| 83 | tracingSer vice.Trace ("Invalid String ret urned"); | |
| 84 | return nul l; | |
| 85 | } | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| 89 | ||
| 90 | pu blic stati c T Deseri alize<T>(s tring json ) | |
| 91 | { | |
| 92 | var clea nJson = Va lidateJson (json); | |
| 93 | var ms = new Memor yStream(En coding.UTF 8.GetBytes (cleanJson )); | |
| 94 | var ser = new Data ContractJs onSerializ er(typeof( T)); | |
| 95 | var resu lt = (T)se r.ReadObje ct(ms); | |
| 96 | ms.Close (); | |
| 97 | return r esult; | |
| 98 | } | |
| 99 | ||
| 100 | pr ivate stat ic string ValidateJs on(string json) | |
| 101 | { | |
| 102 | //Checki ng the Res ponse Stri ng to make sure not null or ma tches comm on XSS | |
| 103 | var Pote ntialXssAt tackExpres sion = "(h ttp(s)*(%3 a|:))|(ftp (s)*(%3a|: ))|(javasc ript)|(ale rt)|(((\\% 3C) <)[^\n ]+((\\%3E) >))"; | |
| 104 | Regex Po tentialXss AttackRege x = new Re gex(Potent ialXssAtta ckExpressi on, RegexO ptions.Ign oreCase); | |
| 105 | if (Pote ntialXssAt tackRegex. IsMatch(js on)) | |
| 106 | { | |
| 107 | thro w new Inva lidDataExc eption("In put is inv alid"); | |
| 108 | } | |
| 109 | else | |
| 110 | { | |
| 111 | retu rn json; | |
| 112 | } | |
| 113 | } | |
| 114 | ||
| 115 | /* | |
| 116 | cl ass MyClie nt : WebCl ient | |
| 117 | { | |
| 118 | protecte d override WebReques t GetWebRe quest(Uri address) | |
| 119 | { | |
| 120 | Http WebRequest request = (HttpWebR equest)bas e.GetWebRe quest(addr ess); | |
| 121 | requ est.Client Certificat es.Add(Get CertKeyVau lt(tracing Service)); | |
| 122 | retu rn request ; | |
| 123 | } | |
| 124 | } | |
| 125 | ||
| 126 | pr ivate stat ic X509Cer tificate2 GetCertKey Vault(Micr osoft.Xrm. Sdk.ITraci ngService tracingSer vice) | |
| 127 | { | |
| 128 | try | |
| 129 | { | |
| 130 | trac ingService .Trace("Re trieve Cer t from Key Vault"); | |
| 131 | ||
| 132 | //co nst string appId = " b39bbc92-2 4f7-4c26-9 61f-fae26b 9290bb"; | |
| 133 | //co nst string secret = "wgnf5EwiM kDQG379L03 1MLpGmxli+ 1WHtSdqGuG XGMs="; | |
| 134 | //co nst string appId = " b39bbc92-2 4f7-4c26-9 61f-fae26b 9290bb"; | |
| 135 | //co nst string secret = "AibIEl9CS CVkD43+oMW d/ke7dRAbx lYCNhwI9Ve WAqA="; | |
| 136 | cons t string a ppId = "2e b8842c-983 b-41a8-84a 2-da4ad41c f4cc"; | |
| 137 | cons t string s ecret = "C Pup2qpsV4j Qwj+b2X6Fs AbYtUveqDR KmoJg+1Ruw OE="; | |
| 138 | cons t string t enantId = "f7c49e36- 971b-42c7- b244-a88ee d6c0bf6"; | |
| 139 | //co nst string certUri = "https:// vanpeastpp mskv1.vaul t.usgovclo udapi.net/ certificat es/np-dws- ppms-nprod /ca92ba898 8c64a6091d 23c6adbdf1 f1a"; | |
| 140 | cons t string c ertUri = " https://va prodsouthp pmskv1.vau lt.usgovcl oudapi.net /secrets/i ws-prod-pp ms-prod/17 72cad9fb25 48a497875b 68b324b806 "; | |
| 141 | ||
| 142 | var token = Ge tToken(app Id, secret , tenantId , tracingS ervice); | |
| 143 | if ( token != n ull) { tra cingServic e.Trace("T oken recei ved"); } | |
| 144 | var cert = Get Certificat eFromKeyVa ult(token. access_tok en, certUr i, tracing Service); | |
| 145 | if ( cert != nu ll) { trac ingService .Trace("Ce rt receive d"); } | |
| 146 | var privateKey = GetPriv ateKeyKeyV ault(token .access_to ken, cert. id, tracin gService); | |
| 147 | if ( privateKey != null) { tracingS ervice.Tra ce("Privat e Key rece ived"); } | |
| 148 | ||
| 149 | var x509Cert = new X509C ertificate 2(privateK ey); | |
| 150 | if ( x509Cert ! = null) { tracingSer vice.Trace ("Cert Cre ated Succe ssfully"); } | |
| 151 | else { tracing Service.Tr ace("Cert Creation F ailure"); } | |
| 152 | ||
| 153 | retu rn x509Cer t; | |
| 154 | } | |
| 155 | catch (W ebExceptio n we) | |
| 156 | { | |
| 157 | trac ingService .Trace("Ge tCertKeyVa ult WebExc eption"); | |
| 158 | retu rn null; | |
| 159 | } | |
| 160 | catch (E xception e ) | |
| 161 | { | |
| 162 | trac ingService .Trace("Ge tCertKeyVa ult Except ion: " + e .Message.T oString()) ; | |
| 163 | retu rn null; | |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | pr ivate stat ic TokenRe sponse Get Token(stri ng clientI d, string clientSecr et, string tenantId, Microsoft .Xrm.Sdk.I TracingSer vice traci ngService) | |
| 168 | { | |
| 169 | try | |
| 170 | { | |
| 171 | trac ingService .Trace("Ge t Token"); | |
| 172 | usin g (var htt pClient = new HttpCl ient()) | |
| 173 | { | |
| 174 | var formCo ntent = ne w FormUrlE ncodedCont ent(new[] | |
| 175 | { | |
| 176 | new KeyVal uePair<str ing, strin g>("resour ce", "http s://vault. usgovcloud api.net"), | |
| 177 | new KeyVal uePair<str ing, strin g>("client _id", clie ntId), | |
| 178 | new KeyVal uePair<str ing, strin g>("client _secret", clientSecr et), | |
| 179 | new KeyVal uePair<str ing, strin g>("grant_ type", "cl ient_crede ntials") | |
| 180 | }); | |
| 181 | ||
| 182 | var respon se = httpC lient | |
| 183 | .PostA sync("http s://login. windows.ne t/" + tena ntId + "/o auth2/toke n", formCo ntent).Get Awaiter() | |
| 184 | .GetRe sult(); | |
| 185 | ||
| 186 | return Des erialize<T okenRespon se>(respon se.Content .ReadAsStr ingAsync() .Result); | |
| 187 | } | |
| 188 | } | |
| 189 | catch (W ebExceptio n we) | |
| 190 | { | |
| 191 | trac ingService .Trace("Ge tToken Web Exception" ); | |
| 192 | retu rn null; | |
| 193 | } | |
| 194 | catch (E xception e ) | |
| 195 | { | |
| 196 | trac ingService .Trace("Ge tToken Exc eption"); | |
| 197 | retu rn null; | |
| 198 | } | |
| 199 | } | |
| 200 | ||
| 201 | pu blic stati c Certific ateRespons e GetCerti ficateFrom KeyVault(s tring toke n, string certificat eUrl, Micr osoft.Xrm. Sdk.ITraci ngService tracingSer vice) | |
| 202 | { | |
| 203 | try | |
| 204 | { | |
| 205 | usin g (var htt pClient = new HttpCl ient()) | |
| 206 | { | |
| 207 | var reques t = | |
| 208 | new Ht tpRequestM essage(Htt pMethod.Ge t, new Uri (certifica teUrl + "? api-versio n=2016-10- 01")); | |
| 209 | request.He aders.Auth orization = new Auth entication HeaderValu e("Bearer" , token); | |
| 210 | ||
| 211 | var respon se = httpC lient.Send Async(requ est).GetAw aiter().Ge tResult(); | |
| 212 | if (respon se.IsSucce ssStatusCo de) { trac ingService .Trace("Su ccessful R esponse re trieving C ertficate from KeyVa ult"); } | |
| 213 | ||
| 214 | return Des erialize<C ertificate Response>( response.C ontent.Rea dAsStringA sync().Get Awaiter(). GetResult( )); | |
| 215 | } | |
| 216 | } | |
| 217 | catch (W ebExceptio n we) | |
| 218 | { | |
| 219 | trac ingService .Trace("Ge tCertifica teFromKeyV ault WebEx ception"); | |
| 220 | retu rn null; | |
| 221 | } | |
| 222 | catch (E xception e ) | |
| 223 | { | |
| 224 | trac ingService .Trace("Ge tCertifica teFromKeyV ault Excep tion"); | |
| 225 | retu rn null; | |
| 226 | } | |
| 227 | } | |
| 228 | pu blic stati c byte[] G etPrivateK eyKeyVault (string to ken, strin g certific ateUrl, Mi crosoft.Xr m.Sdk.ITra cingServic e tracingS ervice) | |
| 229 | { | |
| 230 | try | |
| 231 | { | |
| 232 | usin g (var htt pClient = new HttpCl ient()) | |
| 233 | { | |
| 234 | var reques t = new Ht tpRequestM essage(Htt pMethod.Ge t, new Uri (certifica teUrl + "? api-versio n=2016-10- 01")); | |
| 235 | request.He aders.Auth orization = new Auth entication HeaderValu e("Bearer" , token); | |
| 236 | var respon se = httpC lient.Send Async(requ est).GetAw aiter().Ge tResult(); | |
| 237 | ||
| 238 | var privat eKey = Des erialize<P rivateKeyR esponse>(r esponse.Co ntent.Read AsStringAs ync().GetA waiter().G etResult() ); | |
| 239 | if (respon se.IsSucce ssStatusCo de) { trac ingService .Trace("Su ccessful R esponse re trieving P rivate Key "); } | |
| 240 | return Con vert.FromB ase64Strin g(privateK ey.value); | |
| 241 | } | |
| 242 | } | |
| 243 | catch (W ebExceptio n we) | |
| 244 | { | |
| 245 | trac ingService .Trace("Ge tPrivateKe yKeyVault WebExcepti on"); | |
| 246 | retu rn null; | |
| 247 | } | |
| 248 | catch (E xception e ) | |
| 249 | { | |
| 250 | trac ingService .Trace("Ge tPrivateKe yKeyVault Exception" ); | |
| 251 | retu rn null; | |
| 252 | } | |
| 253 | } | |
| 254 | ||
| 255 | ||
| 256 | public class Tok enResponse | |
| 257 | { | |
| 258 | pu blic strin g token_ty pe { get; set; } | |
| 259 | pu blic strin g expires_ in { get; set; } | |
| 260 | pu blic strin g ext_expi res_in { g et; set; } | |
| 261 | pu blic strin g expires_ on { get; set; } | |
| 262 | pu blic strin g not_befo re { get; set; } | |
| 263 | pu blic strin g resource { get; se t; } | |
| 264 | pu blic strin g access_t oken { get ; set; } | |
| 265 | } | |
| 266 | ||
| 267 | public class Cer tificateRe sponse | |
| 268 | { | |
| 269 | pu blic strin g id { get ; set; } | |
| 270 | pu blic strin g kid { ge t; set; } | |
| 271 | pu blic strin g sid { ge t; set; } | |
| 272 | pu blic strin g x5t { ge t; set; } | |
| 273 | pu blic strin g cer { ge t; set; } | |
| 274 | } | |
| 275 | public class Pri vateKeyRes ponse | |
| 276 | { | |
| 277 | pu blic strin g value { get; set; } | |
| 278 | } | |
| 279 | ||
| 280 | ||
| 281 | public static st ring Seria lizee<T>(T data) | |
| 282 | { | |
| 283 | va r ms = new MemoryStr eam(); | |
| 284 | va r ser = ne w DataCont ractJsonSe rializer(t ypeof(T)); | |
| 285 | se r.WriteObj ect(ms, da ta); | |
| 286 | va r json = m s.ToArray( ); | |
| 287 | ms .Close(); | |
| 288 | ||
| 289 | re turn Encod ing.UTF8.G etString(j son, 0, js on.Length) ; | |
| 290 | } | |
| 291 | ||
| 292 | ||
| 293 | public static Ad dressData ValidateWc DWS(string streetAdd ress, stri ng city, s tring stat e, string zip, ITrac ingService _tracingS ervice) | |
| 294 | { | |
| 295 | tr y | |
| 296 | { | |
| 297 | tracingS ervice = _ tracingSer vice; | |
| 298 | tracingS ervice.Tra ce("Beginn ing Addres s Validati on"); | |
| 299 | tracingS ervice.Tra ce("Addres s Attribue s for Requ est:" + st reetAddres s + ", " + city + ", " + state + ", " + zip); | |
| 300 | ||
| 301 | var addr essData = new Addres sData(); | |
| 302 | ||
| 303 | using (W ebClient w c = new We bClient()) | |
| 304 | { | |
| 305 | //string a ddressStri ng = "http :// DNS . URL /v1.0/Vali dateAddres s?streetAd dress="; | |
| 306 | string pro xyAddressS tring = "h ttps:// DNS . URL /ase/v1.0/ ValidateAd dress?stre etAddress= "; | |
| 307 | ||
| 308 | prox yAddressSt ring += "' " + street Address + "'"; | |
| 309 | prox yAddressSt ring += "& city="; | |
| 310 | prox yAddressSt ring += ci ty; | |
| 311 | prox yAddressSt ring += "& state="; | |
| 312 | prox yAddressSt ring += st ate; | |
| 313 | prox yAddressSt ring += "& zip="; | |
| 314 | prox yAddressSt ring += zi p; | |
| 315 | prox yAddressSt ring = Uri .EscapeUri String(pro xyAddressS tring).Rep lace("#", "%23"); | |
| 316 | ||
| 317 | //var test String = " https:// DNS . URL /v1.0/Vali dateAddres s?streetAd dress="; | |
| 318 | ||
| 319 | trac ingService .Trace("Ad dress Stri ng: " + pr oxyAddress String); | |
| 320 | ||
| 321 | wc.H eaders[Htt pRequestHe ader.Conte ntType] = "applicati on/json"; | |
| 322 | ||
| 323 | trac ingService .Trace("Ma king Call to DWS Add ress Valid ation Func tion"); | |
| 324 | stri ng dwsResp onse = wc. DownloadSt ring(proxy AddressStr ing); | |
| 325 | Addr essDataVal ues addres sDataValue s = Deseri alize<Addr essDataVal ues>(dwsRe sponse); | |
| 326 | if ( addressDat aValues.va lue.Count > 0) | |
| 327 | { | |
| 328 | tracingSer vice.Trace ("Sucessfu l Response from Addr ess Valida tion API") ; | |
| 329 | addressDat a = addres sDataValue s.value[0] ; | |
| 330 | _tracingSe rvice.Trac e("Confide nce Score: " + addres sData.Conf idenceScor e); | |
| 331 | } | |
| 332 | else | |
| 333 | { | |
| 334 | tracingSer vice.Trace ("Unsucces sful Respo nse from A ddress Val idation AP I"); | |
| 335 | } | |
| 336 | retu rn address Data; | |
| 337 | } | |
| 338 | } | |
| 339 | ca tch (WebEx ception we ) | |
| 340 | { | |
| 341 | tracingS ervice.Tra ce("Web Ex ception on call to A ddress Val idation Se rvice:", w e.Message. ToString() ); | |
| 342 | return n ull; | |
| 343 | } | |
| 344 | ca tch (Excep tion e) | |
| 345 | { | |
| 346 | tracingS ervice.Tra ce("Except ion on cal l to Addre ss Validat ion Servic e:", e.ToS tring()); | |
| 347 | return n ull; | |
| 348 | } | |
| 349 | } | |
| 350 | ||
| 351 | ||
| 352 | ||
| 353 | public static Ro otObjectRe sponse Val idateWC(st ring stree tAddress, string cit y, string state, str ing zip, I TracingSer vice _trac ingService ) | |
| 354 | { | |
| 355 | tr y | |
| 356 | { | |
| 357 | tracingS ervice = _ tracingSer vice; | |
| 358 | ||
| 359 | tracingS ervice.Tra ce("Beginn ing Addres s Validati on"); | |
| 360 | ||
| 361 | tracingS ervice.Tra ce("Addres s Attribue s for Requ est:" + st reetAddres s + ", " + city + ", " + state + ", " + zip); | |
| 362 | var addr essData = new RootOb jectRespon se(); | |
| 363 | ||
| 364 | using (M yClient cl ient = new MyClient( )) | |
| 365 | { | |
| 366 | clie nt.Headers [HttpReque stHeader.C ontentType ] = "appli cation/jso n"; | |
| 367 | ||
| 368 | var payload = new RootOb jectReques t | |
| 369 | { | |
| 370 | requestAdd ress = new Address | |
| 371 | { | |
| 372 | addres sLine1 = s treetAddre ss, | |
| 373 | city = city, | |
| 374 | stateP rovince = new StateP rovince | |
| 375 | { | |
| 376 | na me = state | |
| 377 | }, | |
| 378 | zipCod e5 = zip | |
| 379 | } | |
| 380 | }; | |
| 381 | var json = Ser ializee(pa yload); | |
| 382 | ||
| 383 | trac ingService .Trace("Ma king Call to Address Validatio n Servivce "); | |
| 384 | string res ponse = cl ient.Uploa dString(ne w Uri("htt ps:// DNS . URL /address-v alidation/ address/v1 /validate" ), json); | |
| 385 | addr essData = Deserializ e<RootObje ctResponse >(response ); | |
| 386 | if ( addressDat a != null && address Data.addre ssMetaData .deliveryP ointValida tion == "C ONFIRMED") | |
| 387 | { | |
| 388 | tracingSer vice.Trace ("Sucessfu l Response from Addr ess Valida tion API") ; | |
| 389 | } | |
| 390 | trac ingService .Trace("Un successful Response from Addre ss Validat ion API"); | |
| 391 | } | |
| 392 | return a ddressData ; | |
| 393 | } | |
| 394 | ca tch (WebEx ception we ) | |
| 395 | { | |
| 396 | tracingS ervice.Tra ce("Web Ex ception on call to A ddress Val idation Se rvice:", w e.Message. ToString() ); | |
| 397 | throw; | |
| 398 | } | |
| 399 | ca tch (Excep tion e) | |
| 400 | { | |
| 401 | tracingS ervice.Tra ce("Except ion on cal l to Addre ss Validat ion Servic e:", e.ToS tring()); | |
| 402 | return n ull; | |
| 403 | } | |
| 404 | } | |
| 405 | ||
| 406 | ||
| 407 | ||
| 408 | public static Ad dressData ValidateHt tp(string streetAddr ess, strin g city, st ring state , string z ip, ITraci ngService _tracingSe rvice) | |
| 409 | { | |
| 410 | tr y | |
| 411 | { | |
| 412 | tracingS ervice = _ tracingSer vice; | |
| 413 | tracingS ervice.Tra ce("Beginn ing Addres s Validati on"); | |
| 414 | tracingS ervice.Tra ce("Addres s Attribue s for Requ est:" + st reetAddres s + ", " + city + ", " + state + ", " + zip); | |
| 415 | ||
| 416 | var addr essData = new Addres sData(); | |
| 417 | ||
| 418 | using (H ttpClient client = n ew HttpCli ent()) | |
| 419 | { | |
| 420 | //string a ddressStri ng = "http s:// DNS . URL /v1.0/Vali dateAddres s?streetAd dress="; | |
| 421 | string pro xyAddressS tring = "h ttps:// DNS . URL /ase/v1.0/ ValidateAd dress?stre etAddress= "; | |
| 422 | ||
| 423 | prox yAddressSt ring += "' 1239 Vermo nt Ave NW #605'"; | |
| 424 | prox yAddressSt ring += "& city="; | |
| 425 | prox yAddressSt ring += "W ashington" ; | |
| 426 | prox yAddressSt ring += "& state="; | |
| 427 | prox yAddressSt ring += "D C"; | |
| 428 | prox yAddressSt ring += "& zip="; | |
| 429 | prox yAddressSt ring += "2 0005"; | |
| 430 | prox yAddressSt ring = Uri .EscapeUri String(pro xyAddressS tring).Rep lace("#", "%23"); | |
| 431 | ||
| 432 | trac ingService .Trace("Ma king Call to DWS Add ress Valid ation Func tion"); | |
| 433 | ||
| 434 | var response = client.Ge tStringAsy nc(proxyAd dressStrin g).GetAwai ter().GetR esult(); | |
| 435 | ||
| 436 | Addr essDataVal ues addres sDataValue s = Deseri alize<Addr essDataVal ues>(respo nse); | |
| 437 | if ( addressDat aValues.va lue.Count > 0) | |
| 438 | { | |
| 439 | tracingSer vice.Trace ("Sucessfu l Response from Addr ess Valida tion API") ; | |
| 440 | addressDat a = addres sDataValue s.value[0] ; | |
| 441 | } | |
| 442 | } | |
| 443 | tracingS ervice.Tra ce("Unsucc essful Res ponse from Address V alidation API"); | |
| 444 | return a ddressData ; | |
| 445 | } | |
| 446 | ca tch (WebEx ception we ) | |
| 447 | { | |
| 448 | tracingS ervice.Tra ce("Web Ex ception on call to A ddress Val idation Se rvice:", w e.Message. ToString() ); | |
| 449 | throw; | |
| 450 | } | |
| 451 | ca tch (Excep tion e) | |
| 452 | { | |
| 453 | tracingS ervice.Tra ce("Except ion on cal l to Addre ss Validat ion Servic e:", e.ToS tring()); | |
| 454 | throw; | |
| 455 | } | |
| 456 | } | |
| 457 | ||
| 458 | public static Ro otObjectRe sponse Val idate(stri ng streetA ddress, st ring city, string st ate, strin g zip, Mic rosoft.Xrm .Sdk.ITrac ingService tracingSe rvice) | |
| 459 | { | |
| 460 | tr y | |
| 461 | { | |
| 462 | tracingS ervice.Tra ce("Beginn ing Addres s Validati on"); | |
| 463 | //Servic ePointMana ger.Server Certificat eValidatio nCallback += (sender , certific ate, chain , sslPolic yErrors) = > true; | |
| 464 | //Servic ePointMana ger.Securi tyProtocol = Securit yProtocolT ype.Tls12; | |
| 465 | //Servic ePointMana ger.Securi tyProtocol = Securit yProtocolT ype.Ssl3 | SecurityP rotocolTyp e.Tls | Se curityProt ocolType.T ls11 | Sec urityProto colType.Tl s12; | |
| 466 | ||
| 467 | tracingS ervice.Tra ce("Addres s Attribue s for Requ est:" + st reetAddres s + ", " + city + ", " + state + ", " + zip); | |
| 468 | var addr essData = new RootOb jectRespon se(); | |
| 469 | ||
| 470 | using (v ar client = GetHttpC lient(trac ingService )) | |
| 471 | { | |
| 472 | trac ingService .Trace("Se tting Clie nt Base Ad dress"); | |
| 473 | ||
| 474 | ||
| 475 | ||
| 476 | client.Bas eAddress = new Uri(" https:// DNS . URL "); | |
| 477 | var payload = new RootOb jectReques t | |
| 478 | { | |
| 479 | requestAdd ress = new Address | |
| 480 | { | |
| 481 | addres sLine1 = s treetAddre ss, | |
| 482 | city = city, | |
| 483 | stateP rovince = new StateP rovince | |
| 484 | { | |
| 485 | na me = state | |
| 486 | }, | |
| 487 | zipCod e5 = zip | |
| 488 | } | |
| 489 | }; | |
| 490 | ||
| 491 | var json = Ser ializee(pa yload); | |
| 492 | ||
| 493 | var content = new String Content(js on, Encodi ng.UTF8, " applicatio n/json"); | |
| 494 | cont ent.Header s.ContentT ype = new MediaTypeH eaderValue ("applicat ion/json") ; | |
| 495 | ||
| 496 | trac ingService .Trace("Ma king Call to Address Validatio n Servivce "); | |
| 497 | var response = client.Po stAsync("/ address-va lidation/a ddress/v1/ validate", content). GetAwaiter ().GetResu lt(); | |
| 498 | ||
| 499 | if ( response.I sSuccessSt atusCode) | |
| 500 | { | |
| 501 | tracingSer vice.Trace ("Sucessfu l Response from Addr ess Valida tion API") ; | |
| 502 | var result = respons e.Content. ReadAsStri ngAsync(). GetAwaiter ().GetResu lt(); | |
| 503 | if (!strin g.IsNullOr Empty(resu lt)) | |
| 504 | { | |
| 505 | addres sData = De serialize< RootObject Response>( result); | |
| 506 | } | |
| 507 | } | |
| 508 | trac ingService .Trace("Un successful Response from Addre ss Validat ion API"); | |
| 509 | } | |
| 510 | return a ddressData ; | |
| 511 | } | |
| 512 | ca tch (HttpR equestExce ption he) | |
| 513 | { | |
| 514 | tracingS ervice.Tra ce("Http W eb Excepti on on call to Addres s Validati on Service :", he.ToS tring()); | |
| 515 | return n ull; | |
| 516 | } | |
| 517 | ca tch (Excep tion e) | |
| 518 | { | |
| 519 | tracingS ervice.Tra ce("Except ion on cal l to Addre ss Validat ion Servic e:", e.ToS tring()); | |
| 520 | throw; | |
| 521 | } | |
| 522 | } | |
| 523 | ||
| 524 | privat e static H ttpClient GetHttpCli ent(ITraci ngService tracingSer vice) | |
| 525 | { | |
| 526 | tr y | |
| 527 | { | |
| 528 | tracingS ervice.Tra ce("Gettin g HttpClie nt"); | |
| 529 | var clie ntHandler = new WebR equestHand ler(); | |
| 530 | clientHa ndler.Clie ntCertific ates.Add(G etCertKeyV ault(traci ngService) ); | |
| 531 | //client Handler.Cl ientCertif icates.Add (GetLocalC ert()); | |
| 532 | tracingS ervice.Tra ce("Client Handler E stablished "); | |
| 533 | return n ew HttpCli ent(client Handler); | |
| 534 | } | |
| 535 | ca tch(WebExc eption we) | |
| 536 | { | |
| 537 | tracingS ervice.Tra ce("Client Handler W eb Excepti on"); | |
| 538 | throw; | |
| 539 | } | |
| 540 | ca tch(Except ion e) | |
| 541 | { | |
| 542 | tracingS ervice.Tra ce("Client Handler E xception") ; | |
| 543 | throw; | |
| 544 | } | |
| 545 | } | |
| 546 | ||
| 547 | ||
| 548 | ||
| 549 | ||
| 550 | public static X5 09Certific ate2 GetLo calCert() | |
| 551 | { | |
| 552 | va r store = new X509St ore(StoreN ame.My, St oreLocatio n.LocalMac hine); | |
| 553 | st ore.Open(O penFlags.O penExistin gOnly | Op enFlags.Re adOnly); | |
| 554 | string cer tificateSu bjectName = "CN= DNS . URLL , OU=PPMS, O=VA, L=W ashington, S=DC, C=U S"; | |
| 555 | va r cert = s tore.Certi ficates.Fi nd(X509Fin dType.Find BySubjectD istinguish edName, ce rtificateS ubjectName , | |
| 556 | true); | |
| 557 | if (cert.Cou nt < 1) | |
| 558 | { | |
| 559 | throw ne w Exceptio n(string.F ormat("Cou ld not fin d a valid client cer tificate w ith subjec t {0}", | |
| 560 | cert ificateSub jectName)) ; | |
| 561 | } | |
| 562 | ||
| 563 | re turn cert[ 0]; | |
| 564 | } | |
| 565 | ||
| 566 | ||
| 567 | ||
| 568 | ||
| 569 | */ | |
| 570 | } | |
| 571 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.