c# - Visual Studio 2012 + 403.7 Error -


i've been spinning wheels few days not making progress, , suggestions i've found far online haven't quite done trick, here goes:

  1. i have wcf service ties into... not sure type of web service you'd call on other end, kind of rest-ish. url method looks "https://partner.someservice.com/somemethod.asp". cram query string args onto end of , post request server.

  2. the error in vs shows 403, when i've used fiddler see 403.7. before importing cert browsers saw 403.7 well. can inspect request object , see clientcertificates [1] cert specified, i'm pretty sure getting attached.

  3. i've imported .pfx file both machine , local user cert stores. i've run winhttpcertcfg utility number of times in number of ways, following instructions i've seen on msdn , posts.

    winhttpcertcfg -g -c local_machine\my -s [cert] -a [user/aspnet/auth'd users]

    winhttpcertcfg.exe -i [cert.pfx] -c local_machine\my -p [pwd]

  4. i've imported .pfx file chrome. if hit url in chrome, prompt select cert, , can proceed url fine. same behavior in ie.

so seems specific me running in vs, although i'm not sure option haven't checked or permission haven't granted. under project properties on wcf service, have tried "use visual studio development server" , "use local iis web server" same behavior each. missing?

some code:

    private static string dopost(string postdata)     {         string result = null;          var httpwebrequest = (httpwebrequest)webrequest.create(getendpoint());         var encoding = new asciiencoding();         var bytes = encoding.getbytes(postdata);          httpwebrequest.method = "post";         httpwebrequest.contenttype = "application/x-www-form-urlencoded";         httpwebrequest.contentlength = bytes.length;         httpwebrequest.clientcertificates.add(clientcertificate);          using (var stream = httpwebrequest.getrequeststream())         {             stream.write(bytes, 0, bytes.length);             stream.close();              using (var httpwebresponse = httpwebrequest.getresponse())             using (var responsestream = httpwebresponse.getresponsestream())             {                 if (responsestream != null)                 {                     using (var reader = new streamreader(responsestream))                     {                         result = reader.readtoend();                     }                 }             }         }          return result;     } 

and code obtaining cert (in utility class written dev, , seems work fine in production):

    public static x509certificate2 getcertificatebyserial(string serial)     {         var store = new x509store(storename.my, storelocation.localmachine);         store.open(openflags.readonly | openflags.openexistingonly);          var certcoll = store.certificates.find(x509findtype.findbyserialnumber, serial, false);         store.close();          if (certcoll.count == 0)         {             throw new exception(string.format("a certificate serial number of \"{0}\" not installed on server.", serial));         }         return certcoll[0];     } 

i made couple of changes, , able work. one, had change post*, , in doing accidentally left portion of endpoint/url in post data (oops). secondly, included in httpwebrequest:

httpwebrequest.protocolversion = httpversion.version11; 

and last, 403.7 error being caused fiddler intercepting traffic. don't have cert configured in fiddler, come next. once shut down fiddler , formatted post data properly, things worked out.

*switching post had nothing getting resolved, story.

tl;dr didn't format request properly.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -