我创建了一个不使用app.config来配置自身的WCF服务。但是,在某些PC上花费三到四分钟来构建ServiceHost对象。考虑到我的服务有问题,我构建了一个简单的Hello,World服务,并尝试使用它。我有同样的问题。在某些电脑上创建WCF ServiceHost对象需要三到四分钟
根据分析器,所有这段时间都花费在配置服务中。
所以我真的有两个问题。
是否可以禁用从XML读配置?
更重要的是,有没有人有任何想法,为什么这可能需要这么多的时间?
下面是示例服务:
[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;
}
}
我需要设计原因创建服务并在将它作为一个对象,而不是在将它作为一种类型。
如果有更多的信息可以使用,请让我知道。
非常感谢。
嗨Vitaliy,Marc和Shiraz谢谢大家的回应。我尝试了Vitaliy的建议,之后重新启动了我的电脑。这似乎解决了这个问题。不幸的是,我似乎无法登录为我用来创建帖子的帐户,但这似乎已经为我修复了它。再次感谢您的所有建议。 Steve – 2009-10-16 14:42:40
我合并了你的账户。我认为你现在应该可以选择最好的答案。 – Will 2011-04-14 18:14:36