httpwebrequest.getWeb服务中的响应超时

本文关键字:响应超时 服务 getWeb httpwebrequest | 更新日期: 2023-09-27 18:26:33

Q1:以下Web服务从不从req.getResponse()返回并给出超时错误的原因。

webservice代表用户创建httpwebrequest对象,等待回调线程提供证书,然后返回结果。

我在这里可能遗漏了什么?(可能是测试服务器上的一些任务等)。(注意,我在外部Web服务之前使用过httpwebrequest+回调,没有任何问题)

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;
    }
}

httpwebrequest.getWeb服务中的响应超时

原来我在请求对象中缺少代理设置。一旦我启用它,它就会在上运行