How to: Avoiding Cold-Start issues with IIS hosted WCF applications?

后端 未结 2 1117
夕颜
夕颜 2021-01-12 23:05

We have a system where we host a couple of WCF applications in IIS. Some of these applications have a bit of an extended start-up time taking a couple of seconds (more than

相关标签:
2条回答
  • 2021-01-12 23:32

    For those of us running on a version of IIS before 7.5, we are in the process of testing the following solution...

    As mentioned in the original post, the initial idea was to fire off a WebRequest from a service running on each machine to the local web sites (which host the WCF services), but this would be impossible, since they all make use of Host headers, and they all live in a Network load balanced farm.

    We then thought that we could simply provide the custom host headers in the web request to the localhost.

    Turns out you can not update the host header name in a WebRequest. It’s a Read only field.

    Messing with a proxy class makes it work though. See: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/1b35c665-fe32-4433-8877-a62f2d400a8e/

    And a short piece of my test code below in C#.

            WebRequest req = WebRequest.Create("<Correct Host name>");
            req.Proxy = new WebProxy("127.0.0.1");
    
            StreamReader stream = new StreamReader(
                req.GetResponse().GetResponseStream());
    
            StringBuilder sb = new StringBuilder();
    
            String LineString;
    
            while ((LineString = stream.ReadLine()) != null)
            {
                if (LineString.Length > 0)
                    sb.Append(LineString);
            }
            stream.Close();
    
            String response = sb.ToString();
    

    This may not be what the proxy class was intended for, but it seems to work either way.

    Gineer

    Ps. No, you do not need to have any actual proxy server installed on the local host machine.

    0 讨论(0)
  • 2021-01-12 23:36

    Excellent. Thanks Dercsár.

    After a quick Google, I found the following arcticle on the subject: Using the IIS Application Warm-Up Module

    The limitations here are that this is only available on Windows 2008 R2 with IIS 7.5. Although our client is in the process of upgrading to Win 2K8R2, this may still be some time off.

    Does anyone know of a solution that would work for Windows 2003 with IIS 6 or will we have to write something do make this work?

    Gineer

    0 讨论(0)
提交回复
热议问题