WCF - 403,直到我重新启动AppPool

时间:2017-12-04 12:37:54

标签: asp.net wcf iis http-status-code-403 application-pool

我有一个相当好奇(a.k.a.恼人的)问题。

我在本地工作站上设置了 WCF Web服务存储库(仍在开发中)。 我已经在本地IIS下发布了具有自己的专用应用程序池的项目:.NET v4.0.30319,集成管道模式。

在此解决方案中的一些Web服务中,我对其他外部https Web服务(通过Internet)进行了一些休息调用。

之后,让我们说一天甚至更少,所发布的解决方案所做的所有其他调用最终都会出现403 Forbidden错误。 如果我重新启动运行此解决方案的应用程序池,所有这些403错误都消失了 - 当然,再过几个小时或一天的时间 - 这就是让我疯狂的部分!!!

如果我只是重新启动应用程序池,那么在代码或其他任何内容中没有任何更改,ws调用将再次开始工作。 此外,当我遇到403错误时,如果我在调试模式下运行项目(VS * IIS express),对外部Web服务的调用工作正常(没有403)。

我可以提供代码示例,但如上所述,我并不认为这是与代码相关的问题,因为一旦我重新启动应用程序池,一切都会重新开始工作......

有没有人遇到过这样烦人的问题?

请帮忙!

以下是应用程序池的设置。

enter image description here

稍后编辑:

也许值得一提的是,对于外部Web服务的REST调用,我使用相同的泛型方法。这是代码:

public static string GetRestCall(string requestUri, string contentType, string method, string postData, bool removeServerCerticateValidatioCallBack = true,bool byPassCachePolicy = true, 
 bool keepAliveRequest = true, string userAgent = null, string acceptHeaderString = null, string referer = null, CookieContainer cookieContainer = null, int timeOutRequest = 60000)
{
   try
        {
            if (removeServerCerticateValidatioCallBack == true)
            {
                ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
                {
                    return true;
                };
            }

        //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@requestUri);

        req.KeepAlive = keepAliveRequest;
        if (byPassCachePolicy == true)
        {
            RequestCachePolicy cachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
            req.CachePolicy = cachePolicy;
            req.Expect = null;
        }
        if (!string.IsNullOrEmpty(method))
            req.Method = method;
        if (!string.IsNullOrEmpty(acceptHeaderString))
            req.Accept = acceptHeaderString;
        if (!string.IsNullOrEmpty(referer))
            req.Referer = referer;
        if (!string.IsNullOrEmpty(contentType))
            req.ContentType = contentType;
        if (!string.IsNullOrEmpty(userAgent))
        { req.UserAgent = userAgent; }
        else
        {
            req.UserAgent = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36";
        }
        if (cookieContainer != null)
            req.CookieContainer = cookieContainer;
        req.Timeout = timeOutRequest;

        using (Stream stm = req.GetRequestStream())
        {
            using (StreamWriter stmw = new StreamWriter(stm))
            {
                stmw.Write(postData);
            }
        }

        using (WebResponse response = req.GetResponse() as WebResponse)
        {
            using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
            {
                string responseStream = streamReader.ReadToEnd();
                return responseStream;
            }
        }
    }
    catch
    {
        throw;
    }
}

0 个答案:

没有答案
相关问题