I created a WCF service that does not use app.config to configure. However, on some PCs, it takes three to four minutes to create a ServiceHost object. Thinking that something was wrong with my service, I built a simple Hello, World service and tried this with it. I have the same problem.
According to the profiler, all this time is spent reading in the configuration for the service.
So, I have two questions.
Is it possible to disable read configuration from XML?
More importantly, does anyone know why this might take such an excessive amount of time?
Here is an example 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);
host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "Test");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
return;
}
}
I need to create reasons for creating the service and pass it as an object, and not pass it as a type.
- , , .
.