Creating a WCF ServiceHost object takes three to four minutes on some PCs

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2009-10-16T12:22:04Z Indexed on 2010/04/08 16:03 UTC
Read the original article Hit count: 516

Filed under:
|

Hello,

I have created a WCF service which does not use the app.config to configure itself. However, it takes three to four minutes on some PCs to construct the ServiceHost object. Thinking there was something wrong with my service, I constructed a simple Hello, World service and tried it with that. I have the same issue.

According to the profiler, all this time is spent reading in configuration for the service.

So I have two questions really.

  1. Is it possible to disable reading config from the XML?

  2. More importantly, does anyone have any idea why this might be taking such an inordinate amount of time?

Here is the sample service:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    string GetString();
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class MyService : IMyService
{
    public string GetString()
    {
        return "Hello, world!";
    }
}

class Program
{
    static void Main(string[] args)
    {
        Uri epAddress = new Uri("http://localhost:8731/Test");
        Uri[] uris = new Uri[] { epAddress };

        MyService srv = new MyService();
        ServiceHost host = new ServiceHost(srv, uris);  // this line takes 3-4 minutes

        host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "Test");
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        host.Description.Behaviors.Add(smb);

        host.Open();

        return;
    }
}

I need for design reasons to create the service and pass it in as an object, rather than passing it in as a type.

If there's any more information that can be of use, please let me know.

Many thanks.

© Stack Overflow or respective owner

Related posts about wcf

Related posts about servicehost