views:

288

answers:

4

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.

A: 

Is the server connected to the internet?

If not, try the following:

  1. Open Internet Explorer
  2. Tools -> Internet Options -> Advanced Tab
  3. Scroll down to Security and disable 'Check for publisher's certificate revocation' and 'Check for Signatures on downloaded programs'

In some cases doing this speeds up lots of seemingly unrelated processes on your PC, including communication and startup speed of different ms programs (especially Visual Studio).

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

No - but you can always either just delete the app.config file if you're self-hosting, or just not have the <system.serviceModel> section in your app.config/web.config.

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

No, I don't - but I see you're using the default wsHttpBinding.

Question is: does this behave the same with all bindings? wsHttpBinding is a pretty heavy-weight binding with support for lots of features.

Do you see the same amount of time spent when using e.g. the basicHttpBinding or the netTcpBinding ??

Marc

marc_s
A: 

If something takes a long time without any apparent reason, it is often that there is some locking and it is waiting for a timeout.

I am guessing that it is something to do with port 8731.

  • Do you have anything else listening on that port?
  • Do you have a firewall that could be giving you problems?
Shiraz Bhaiji
A: 

Hi Vitaliy, Marc and Shiraz

Thank you all for your responses.

I tried Vitaliy's suggestion, and rebooted my PC afterwards. This seems to have resolved the issue.

Unfortunately I can't seem to login as the same account that I used to create the post, but this certainly seems to have fixed it for me.

Once again, thanks for all your suggestions.

Steve

Steve