简体   繁体   中英

httpwebrequest.getResponse timesout in webservice

Q1: Any idea why the below webservice never returns from req.getResponse() and gives timeout error.

The webservice creates the httpwebrequest object on behalf of the user and waits for the callback thread to provide the certificate, and then returns the result.

Any thing I may be missing here?( may be some persmission on the test server etc). ( note that I have used httpwebrequest+callback before outside webservice without any problem)

Q2: Is there a syncrhonous way of retrieving cert from httpsserver rather getting in callback?

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

It turned out that I was missing the proxy setting in the request object. Once I enable it , it work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM