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.
Is it possible to disable reading config from the XML?
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.