我创建了一个不使用app.config进行自我配置的WCF服务。但是,在某些PC上需要三到四分钟来构造ServiceHost对象。考虑到我的服务有问题,我构建了一个简单的Hello,World服务并尝试了该服务。我有同样的问题。
根据探查器,所有这些时间都花在阅读服务的配置上。
所以我真的有两个问题。
是否可以禁用从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;
}
}
由于设计原因,我需要创建服务并将其作为对象传递,而不是作为类型传递。
如果还有其他可用信息,请告诉我。
非常感谢。
最佳答案
服务器连接到互联网了吗?
如果没有,请尝试以下操作:
开启Internet Explorer
工具-> Internet选项->高级选项卡
向下滚动到“安全性”并禁用“检查发布者的证书吊销”
和“检查下载程序上的签名”
在某些情况下,这样做可以加快PC上许多看似无关的进程的速度,包括不同ms程序(尤其是Visual Studio)的通信和启动速度。
关于wcf - 在某些PC上,创建WCF ServiceHost对象需要三到四分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1577730/