簡體   English   中英

Web服務中的httpwebrequest.getResponse超時

[英]httpwebrequest.getResponse timesout in webservice

Q1:為什么下面的Web服務永遠不會從req.getResponse()返回並給出超時錯誤的任何想法。

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

我在這里可能會缺少任何東西嗎?(可能是對測試服務器的許可等)。 (請注意,我在外部網絡服務之前使用了httpwebrequest + callback沒問題)

Q2:是否有一種從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;
    }
}

原來,我在請求對象中缺少代理設置。 一旦啟用它,它就可以工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM