2012-03-02 53 views
0

Q1: 任何想法爲什麼下面的webservice永遠不會從req.getResponse()返回並給出超時錯誤。httpwebrequest.getResponse超時在webservice

webservice代表用戶創建httpwebrequest對象並等待回調線程提供證書,然後返回結果。

我可能在這裏丟失的任何東西?(可能是在測試服務器等的一些執行)。 (請注意,我已在外部webservice之前使用httpwebrequest +回調沒有任何問題)

問題2:是否有從httpsserver獲取證書的同步方法,而不是進入回調?

[WebService(Namespace = "http://testserver")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService] 
public class main : System.Web.Services.WebService 
{ 

    static main pointer; 

    private static bool ValidateRemoteCertificate(
object sender, 
X509Certificate certificate, 
X509Chain chain, 
SslPolicyErrors policyErrors 
) 
    { 
     X509Certificate2 cert = new X509Certificate2(certificate); 
     HttpWebRequest wbr= (HttpWebRequest)sender; 

     pointer.Application[wbr.RequestUri.ToString()] = cert.Thumbprint; 
     return true; 
    } 



    public main() 
    { 
     ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateRemoteCertificate);    
     pointer = this; 
    } 
    [WebMethod] 
    public string verifyCertificate(string thumb, string sslsite) 
    { 

     string result = ""; 


     try 
     { 
      HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sslsite); 
      pointer.Application[req.RequestUri.ToString()] = null; 

      req.GetResponse(); 
      /* while (Application[req.RequestUri.ToString()] == null) 
      { 
       Thread.CurrentThread.Join(1000); 
      } 
      */ 
      result = (string)Application[req.RequestUri.ToString()]; 
     } 
     catch (Exception e) 
     { 
      result = e.ToString(); 
     } 
     return result; 
    } 
} 

回答

0

事實證明,我錯過了請求對象中的代理設置。一旦我啓用它,它就可以工作

+0

你可以接受你自己的答案,僅供參考。 – 2012-10-10 20:34:57

相關問題