2012-09-07 23 views
9

Possible Duplicate:
The request was aborted: Could not create SSL/TLS secure channelअनुरोध निरस्त किया गया था: SSL/TLS सुरक्षित चैनल

मैं एक ग्राहक के पक्ष प्रमाण पत्र के साथ एक http अनुरोध भेजने के लिए कोशिश कर रहा हूँ नहीं बना सका। फ़ाइल, इस मामले में .p12 फ़ाइल। System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

मैं, जहां एप्लिकेशन पूल पहचान "स्थानीय सिस्टम" है (विंडोज 7 पर) IIS7.5 पर इस डिबगिंग हूँ: हालांकि जब यह लाइन responseStream = httpRequest.GetRequestStream(); तक पहुँच जाता है यह एक WebException फेंकता है।

मैं इस समस्या को कैसे हल करूं?

 System.IO.Stream responseStream = null; 
     string errorString = string.Empty; 
     ; 
     string postData = string.Empty; 
     HttpWebRequest httpRequest = null; 
     System.Text.Encoding Encoding = new System.Text.UTF8Encoding(); 
     try 
     { 
      XmlDocument orderXml = new XmlDocument(); 
      orderXml.Load(@"c:\xmlfile.xml"); 
      postData = orderXml.InnerXml; 

      byte[] byte1 = Encoding.GetBytes(postData); 

      httpRequest = (HttpWebRequest)WebRequest.Create("https://testurl.com/SOAP_v1_0/"); 
      httpRequest.Method = "POST"; 
      httpRequest.Timeout = 9000; 
      httpRequest.KeepAlive = false; 
      httpRequest.ContentType = "text/xml; charset=" + "utf-8"; 
      httpRequest.ContentLength = byte1.Length; 

      X509Certificate2 certificate = new X509Certificate2(@"c:\file.p12", "password", X509KeyStorageFlags.Exportable); 
      X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); 

      try 
      { 
       store.Open(OpenFlags.ReadWrite); 

       if (!store.Certificates.Contains(certificate)) 
       { 
        store.Add(certificate); 
       } 

       int indexOfCertificate = store.Certificates.IndexOf(certificate); 
       certificate = store.Certificates[indexOfCertificate]; 
      } 

      finally 
      { 
       store.Close(); 
      } 

      httpRequest.ClientCertificates.Add(certificate); 

      responseStream = httpRequest.GetRequestStream(); 

      responseStream.Write(byte1, 0, byte1.Length); 
     } 
     catch (WebException webExcp) 
     { 
      errorString += "Error message: " + webExcp.Message; 

      // Get the WebException status code. 
      WebExceptionStatus status = webExcp.Status; 

      if (status == WebExceptionStatus.ProtocolError) 
      { 
       // Get HttpWebResponse so that you can check the HTTP status code. 
       HttpWebResponse httpResponse = (HttpWebResponse)webExcp.Response; 
       errorString += "; The server returned protocol error " + httpResponse.StatusCode + " - " + httpResponse.StatusCode; 
       httpResponse.Close(); 
      } 
     } 
     catch (Exception e) 
     { 
      errorString += "Error message: " + e.Message; 
     } 
     finally 
     { 
      if (responseStream != null) 
      { 
       responseStream.Close(); 
      } 
     } 
    } 

जब एक का पता लगाने के साथ चल रहे लोग इन इन त्रुटि specifing पंक्तियां हैं:

System.Net Information: 0 : [4968] SecureChannel#2399524 - Certificate is of type X509Certificate2 and contains the private key. 

System.Net Information: 0 : [4968] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc  = System.Net.SecureCredential) 

System.Net Error: 0 : [4968] AcquireCredentialsHandle() failed with error 0X8009030D. 

System.Net Information: 0 : [4968] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Outbound, scc  = System.Net.SecureCredential) 

System.Net Error: 0 : [4968] AcquireCredentialsHandle() failed with error 0X8009030D. 
System.Net.Sockets Verbose: 0 : [4968] Socket#59311937::Dispose() 

System.Net Error: 0 : [4968] Exception in the HttpWebRequest#50160154:: - The request was aborted: Could not create SSL/TLS secure channel. 

System.Net Error: 0 : [4968] Exception in the HttpWebRequest#50160154::EndGetRequestStream - The request was aborted: Could not create SSL/TLS secure channel. 
+0

क्या आप ब्राउज़र के साथ उसी यूआरएल में सफलतापूर्वक नेविगेट कर सकते हैं? क्या यह सफलतापूर्वक एसएसएल/टीएलएस सत्र स्थापित करता है? – Richard

+0

मुझे नहीं मिला "इंटरनेट एक्सप्लोरर वेबपृष्ठ प्रदर्शित नहीं कर सकता" – Rutger

+0

तो त्रुटि पृष्ठ पर दिए गए लिंक के माध्यम से विवरण देखें। आपको यह जानने की जरूरत है कि एसएसएल/टीएलएस चैनल क्यों नहीं बनाया जा सकता है। उस जानकारी के बिना हम क्लाइंट और सर्वर पर कॉन्फ़िगरेशन सेटिंग्स पर अनुमान लगा रहे हैं। – Richard

उत्तर

31

आप अपने ऐप के लिए system.net लॉग बनाना होगा। आपको एक myapp.exe.config कॉन्फ़िगरेशन फ़ाइल बनाने की आवश्यकता होगी और इसमें निम्न डालेंगे।

<?xml version="1.0" encoding="UTF-8"?> 

<configuration> 
    <system.diagnostics> 
     <trace autoflush="true" /> 
     <sources> 
      <source name="System.Net"> 
       <listeners> 
        <add name="System.Net" /> 
       </listeners> 
      </source> 
      <source name="System.Net.Sockets"> 
       <listeners> 
        <add name="System.Net" /> 
       </listeners> 
      </source> 
      <source name="System.Net.Cache"> 
       <listeners> 
        <add name="System.Net" /> 
       </listeners> 
      </source> 
     </sources> 
     <sharedListeners> 
      <add 
       name="System.Net" 
       type="System.Diagnostics.TextWriterTraceListener" 
       initializeData="System.Net.trace.log" 
      /> 
     </sharedListeners> 
     <switches> 
      <add name="System.Net" value="Verbose" /> 
      <add name="System.Net.Sockets" value="Verbose" /> 
      <add name="System.Net.Cache" value="Verbose" /> 
     </switches> 
    </system.diagnostics> 
</configuration> 

आप इस कॉन्फ़िग फ़ाइल के साथ चलाते हैं, तो यह एक लॉगफ़ाइल system.net.trace.log कहा जाता है पैदा करेगा। उस फ़ाइल में अधिक जानकारी होगी कि यह क्यों विफल रहा है।

+0

ट्रेस लॉग – Rutger

+0

के त्रुटि भाग के साथ अद्यतन प्रश्न यदि आप अधिक विस्तृत त्रुटि संदेश नहीं चाहते हैं तो 'traceOutputOptions = "DateTime, ProcessId, ThreadId, Callstack" 'sharedListener'' System.Net 'के गुणों के रूप में जोड़ें। इस तरह: '< नाम =" System.Net " प्रकार =" System.Diagnostics.TextWriterTraceListener " traceOutputOptions =" ​​दिनांक समय, ProcessID, threadid, Callstack " initializeData =" System.Net.trace.log " /जोड़ने > ' – Ogglas

संबंधित मुद्दे

 संबंधित मुद्दे