Writing a secure client app trying to use .NET framework. If I try straight html, server pop-sup an authenticate window and the xml gets digested. Use a WebFrom with HttpWebRequest/Response objects and no dice. Did lots of homework, any ideas from the pro's?
Code:try{ string postData="<?xml version="1.1"?>" //XML skinnied down for brevity. ServicePointManager.CertificatePolicy = new CertPolicy(); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://emkttrn.pjm.com/emkt/xml/query"); X509Certificate myCert = X509Certificate.CreateFromCertFile(@"c:\pjmtest.cer"); X509CertificateCollection x509 = myRequest.ClientCertificates; x509.Add (myCert); myRequest.ClientCertificates.Add(myCert); ASCIIEncoding encodedData=new ASCIIEncoding(); byte[] byteArray=encodedData.GetBytes(postData); myRequest.Method="POST"; myRequest.ContentType="text/xml"; myRequest.ContentLength=byteArray.Length; WebHeaderCollection myWebHeaderCollection = myRequest.Headers; myWebHeaderCollection.Add("POST:/emkt/xml/query HTTP/1.1"); myWebHeaderCollection.Add("SOAPAction:/emkt/xml/query"); //Place XML after headers. Stream newStream=myRequest.GetRequestStream(); newStream.Write(byteArray,0,byteArray.Length); newStream.Close(); //Wait for a response... HttpWebResponse myResponse=(HttpWebResponse)myRequest.GetResponse(); Stream receiveStream = myResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader( receiveStream, encode ); Char[] read = new Char[256]; int count = readStream.Read( read, 0, 256 ); while (count > 0) { String str = new String(read, 0, count); if(count==1) {TextBox2.Text = str;}; TextBox2.Text = TextBox2.Text + "\n" + str; count = readStream.Read(read, 0, 256); } readStream.Close(); myResponse.Close(); } //Textbox 2 on webform tells me that the server connection is closed... catch(System.Net.WebException v) {TextBox2.Text = v.Message;} } } public class CertPolicy : ICertificatePolicy { public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest request, int problem) { return true; } }



LinkBack URL
About LinkBacks


