在某些 PC 上创建 WCF ServiceHost 对象需要三到四分钟

发布于 2024-08-08 10:54:17 字数 1256 浏览 4 评论 0 原文

我创建了一个 WCF 服务,它不使用 app.config 来配置自身。但是,在某些 PC 上,构建 ServiceHost 对象需要三到四分钟。我认为我的服务有问题,因此构建了一个简单的 Hello, World 服务并尝试了它。我有同样的问题。

根据探查器,所有这些时间都花在读取服务的配置上。

所以我真的有两个问题。

  1. 是否可以禁用从 XML 读取配置?

  2. 更重要的是,有人知道为什么这可能会花费如此多的时间吗?

这是示例服务:

[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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自控 2024-08-15 10:54:17

服务器是否已连接到互联网?

如果没有,请尝试以下操作:

  1. 打开 Internet Explorer
  2. 工具 ->互联网选项 ->高级选项卡
  3. 向下滚动到安全性并禁用“检查发布者的证书吊销”
    和“检查下载程序的签名”

在某些情况下,这样做会加快 PC 上许多看似不相关的进程的速度,包括不同 MS 程序(尤其是 Visual Studio)的通信和启动速度。

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).

新一帅帅 2024-08-15 10:54:17

<块引用>

  1. 是否可以禁止从 XML 读取配置?

否 - 但如果您是自托管,您始终可以删除 app.config 文件,或者在 app.config/web.config 中没有 部分。

<块引用>

  • 更重要的是,有人知道为什么这会花费如此多的时间吗?
  • 不,我不知道 - 但我看到您正在使用默认的 wsHttpBinding。

    问题是:所有绑定的行为都相同吗? wsHttpBinding 是一个相当重量级的绑定,支持许多功能。

    您是否发现使用 basicHttpBindingnetTcpBinding 时花费的时间相同?

    马克

    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

    仅冇旳回忆 2024-08-15 10:54:17

    如果某件事在没有任何明显原因的情况下花费了很长时间,则通常是存在某种锁定并且正在等待超时。

    我猜这与端口 8731 有关。

    • 您还有其他东西在监听该端口吗?
    • 您的防火墙是否可能给您带来问题?

    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?
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文