I am trying to send XML data through SSL with client certificate. This is a console application which posts data outside of our company(external service). Here is my Code. (VS2003, Framework 1.1 with SP1).
public static string SendImageDocument(XmlDocument doc, string url, WebProxy webProxy, X509Certificate cert) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "text/xml"; request.KeepAlive = true; request.Accept = "text/xml"; request.Method = "POST"; request.Proxy = webProxy; request.ClientCertificates.Add(cert); ServicePointManager.CertificatePolicy = new SSLCertificate();
using (Stream requestStream = request.GetRequestStream()) { doc.Save(requestStream); }
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode != HttpStatusCode.OK) { string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); }
StreamReader reader = new StreamReader(response.GetResponseStream()); string result = reader.ReadToEnd(); response.Close(); reader.Close(); return result; }
The certificate was installed in the server. I did generate pfx file with Private key from the server. Took the pfx file and installed the certificate in my development machine both Machine and User account. Generated .cer file without private key from the install and kept it in local folder.
request.ClientCertificates.Add(cert); The above line in the code did not give any error. I was able to browse request object and see the certificate information. I tried reading the certificate in both ways of reading certificate from .cer file as well as reading directly from the store using WSE 2.0.
HttpWebResponse response = (HttpWebResponse) request.GetResponse(); When I send this request, the external service people are saying they are not seeing the certificate in the request. They are able to see my header and body XML. I tried many different ways, still no luck. I tried Fiddler and SOAP Trce Toolkit to capture the output request message from my program, I was able to see the Header and Body XML. I can not see the Certificate in the message.
1. Can I able to see certificate in the request through such tracing tools Is there any 2. request.ClientCertificates.Add(cert); If this line did not prooduce any error, why my certificate is not sent 3. Is there any thing wrong in the code 4. Is there anything wrong in the procedure I followed to install the certificate
Any help will be appreciated.
Thanks, Vijay
.NET Development21
|