简体   繁体   English

WCF服务可以从客户端调用方法吗?

[英]Can a WCF service call a method not from the client?

I've created a WCF service application containing a client, contract and a service. 我创建了一个包含客户端,合同和服务的WCF服务应用程序。 I use the client to call methods implemented in the service. 我使用客户端来调用服务中实现的方法。

Is there a way to have a timer in the service and to set its interval to tick and to have a method that is executing during the time the service is being called. 有没有一种方法可以在服务中包含一个计时器,并将其间隔设置为滴答,并可以在服务被调用期间执行一种方法。

I tried to create a constructor to the service (static and non-static) but it didn't work. 我试图为服务创建一个构造器(静态和非静态),但是它没有用。

I thought about creating a 3rd party client, which will execute a method implemented in the service which will do what I need. 我考虑过要创建一个第三方客户端,该客户端将执行在服务中实现的方法,该方法将完成我需要的工作。

Thanks, Oded. 谢谢,奥德。

If you want something running while the service is called, then you could do it from the client: 如果要在调用服务时运行某些程序,则可以从客户端执行该操作:

  • Call start process from the client 从客户端开始通话
  • Call the service from the client 从客户致电服务
  • Call stop process from the client 客户端的呼叫停止过程

You could also do it on the server side: 您也可以在服务器端执行此操作:

  • Your first line in the service is start process 服务的第一行是启动过程
  • Your last line in the service is stop process 服务的最后一行是停止过程

Note you must be carefull about error handling, otherwise you will end up with many orphaned processes. 请注意,您必须谨慎对待错误处理,否则最终将导致许多孤立的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM