WCF Web/ServiceHost - 单例和初始化

发布于 2024-09-02 12:15:28 字数 563 浏览 4 评论 0原文

我有一些服务类,它定义为 InstanceContextMode.Single,并且在托管应用程序中众所周知。 (主机创建一个实例,并将其传递给 WebServiceHost)

托管应用:

WebServiceHost host = null;
SomeService serviceInstance = new SomeService("text", "more text");
host = new WebServiceHost(serviceInstance, baseUri);
Problem:
When I go to use the variables initialised when the service is created (ie, when a call is made to the service), they are either null or empty...

我是否错误地假设在托管应用程序中初始化的实例用于对 WebServiceHost 的每个请求?

这里的任何指示都会很棒。

I have some Service class which is defined as InstanceContextMode.Single, and is well known in the hosting application. (The host creates an instance, and passes that to the WebServiceHost)

Hosting app:

WebServiceHost host = null;
SomeService serviceInstance = new SomeService("text", "more text");
host = new WebServiceHost(serviceInstance, baseUri);

Problem:
When I go to use the variables initialised when the service is created (ie, when a call is made to the service), they are either null or empty...

Am I wrong in assuming that as the instance being initialised in the hosting application is used for each request to the WebServiceHost?

Any pointers here would be great.

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

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

发布评论

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

评论(1

糖粟与秋泊 2024-09-09 12:15:28

你的假设对我来说似乎是正确的。
您是否在服务构造函数中放置了正确的代码?

Your assumption seems correct to me.
Did you put the right code in the service constructor?

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