none
asp.net 1.1 webservice call RRS feed

  • Question

  • How can make a http webrequest using a pfx certificate(p12) in asp.net v1.1

    I have to send the certificate and the password.I tried with soap UI and i can get a response but cannot send from code.First of all i do not have the send password option in this version and if i send the certificate without the password i get an error:"input data cannot be coded as a valid certificate"

    thanks


    Wednesday, January 9, 2013 4:04 PM

Answers

All replies

  • Hi,

    You need import the certificate and the private key to the relevant certificates region for your operating system.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 11, 2013 3:41 AM
    Moderator
  • Yes but I need to send the certificate and private key from my c# code.I can t find a way to do this.
    Friday, January 11, 2013 11:16 AM
  • Hi,

    You can utilize the HttpWebRequest object.

    HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(strQueryURL);
    
        X509Certificate cer = new X509Certificate(System.Web.HttpContext.Current.Server.MapPath(setting.PfxFile), setting.key);
    
        httpRequest.ClientCertificates.Add(cer);

    This post talks on how to send a client certificate by using the HttpWebRequest.

    http://support.microsoft.com/kb/895971?wa=wsignin1.0

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 15, 2013 3:19 AM
    Moderator


  • Here I am again...I have solved the  certificate issue sort of...I have upgraded my framework to  .net 2 version and attached with x509Certificate2 the pfx file to my request.Not getting unauthorized anymore.But another error:

    Error in HttpSOAPRequest: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
      at System.Net.HttpWebRequest.GetResponse()

    and this xml:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><soapenv:Fault><faultcode xmlns:fw="http://fw3rd.services.telefonica.es/fault"></faultcode><faultstring> General Security Error</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

    I get the same response from webserver if I test with soap ui and write a bad  request.So I think something is worng with my request.

    I have composed the soap string right , converted it to byte and I am using this code for sending request:

    Object[] obj_params = {subject_type,subject,content_selector,content_value,on_subscribe};
                string message = String.Format (SoapEnvelope, obj_params);
                byte [] message_bytes = System.Text.Encoding.ASCII.GetBytes(message);
                Uri soapUrl = new Uri (SoapUri);
                t.Write(message);
                t.Warn(soapUrl.ToString());


                req = (HttpWebRequest)WebRequest.Create(soapUrl);
               
                req.ContentType = "text/xml charset=utf-8,soap+xml,application/soap+xml";
                req.Method = "POST";
                req.KeepAlive = false;
                req.Accept = "application/soap+xml,soap+xml, application/dime, multipart/related, text/*";
                req.Headers.Add("SOAPAction", "\"http://yyyy/xxx/getcccc\"");
                t.Write(req.Headers.ToString());
                req.ContentLength = message_bytes.Length;    
                req.Timeout = 15000;
                req.ClientCertificates.Add(cer);

    t.Warn(message_bytes.ToString());
                Stream req_str = req.GetRequestStream ();
                req_str.Write (message_bytes, 0, message_bytes.Length);
                req_str.Flush();
                message_bytes = null;
                req_str.Close();
                req_str = null;
                t.Warn("Sending request");
                
                try
               
                {

                    HttpWebResponse myHttpWebResponse= (HttpWebResponse)req.GetResponse();
                    t.Write("Getting response");
                    Stream streamResponse=myHttpWebResponse.GetResponseStream();
                    StreamReader streamRead = new StreamReader( streamResponse );
                    result = streamRead.ReadToEnd();
                    t.Warn(result);
                    streamRead.Close();
                    streamResponse.Close();
                    myHttpWebResponse.Close();


    any advise would be great.

    thanks
    Friday, February 1, 2013 3:42 PM
  • Hi,

    I'd suggest you enable tracing for your service help to dignose the actual issue, view the log file with SvcTraceViewer.exe.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 4, 2013 5:23 AM
    Moderator