Thursday, 15 April 2010

c# - Access a service in console application with service requies a certificate -



c# - Access a service in console application with service requies a certificate -

i trying read info below service request url.when open in browser see info .but when want same using consoleapplication didn't work.

https://wb01.miracast.com/primary/services/requestlist/getrequestlist?id=80fc46f4&queryby=requestid&format=xml

one thing noticed asks me select certificate , when select certificate(in case sr.dns.miracast.com(it machine auth ca 2) ), returns info , displays in browser. have certificate installed in personal, trustedrootauthority in desktop code running in visual studio.

now how accomplish same using c# console application code. mean how specify certificate code ?

i tried below throws not found error in reposne grab block.

private void button_click(object sender, routedeventargs e) { // retrieve avatar image web string avataruri = "https://wb01.miracast.com/primary/services/requestlist/getrequestlist?id=80fc46f4&queryby=requestid&format=xml"; httpwebrequest request = (httpwebrequest)httpwebrequest.create(avataruri); request.begingetresponse(getavatarimagecallback, request); } private void getavatarimagecallback(iasyncresult result) { httpwebrequest request = result.asyncstate httpwebrequest; if (request != null) { seek { webresponse response = request.endgetresponse(result); //avatarimg = texture2d.fromstream( // graphics.graphicsdevice, // response.getresponsestream()); } grab (webexception e) { // gamertag = "gamertag not found."; return; } } }

after attaching same certificate through code worked.

string avataruri = "https://wb01.miracast.com/primary/services/requestlist/getrequestlist?id=80fc46f4&queryby=requestid&format=xml"; httpwebrequest request = (httpwebrequest)httpwebrequest.create(avataruri); request.method = "get"; // post method x509certificate cert = x509certificate.createfromcertfile(@"c:\users\kim\desktop\oas-test.cer"); request.clientcertificates.add(cert); // attaching certificate request system.net.servicepointmanager.certificatepolicy = new trustallcertificatepolicy(); request.usedefaultcredentials = true; request.proxy.credentials = system.net.credentialcache.defaultcredentials; httpwebresponse wresp = (httpwebresponse)request.getresponse(); encoding enc = system.text.encoding.getencoding(1252); streamreader loresponsestream = new streamreader(wresp.getresponsestream(), enc); string response = loresponsestream.readtoend(); loresponsestream.close(); wresp.close();

c# ssl

No comments:

Post a Comment