WCF Web/ServiceHost - 单例和初始化
我有一些服务类,它定义为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的假设对我来说似乎是正确的。
您是否在服务构造函数中放置了正确的代码?
Your assumption seems correct to me.
Did you put the right code in the service constructor?