开发者

Is it ok to call a service method in an other service method ? (WCF)

开发者 https://www.devze.com 2022-12-22 07:03 出处:网络
Sample code: public class Service1 { public int Service1() { 开发者_开发百科.... } } public class Service2

Sample code:

public class Service1
{
    public int Service1()
    {
      开发者_开发百科  ....
    }
}

public class Service2
{
    public int Service2()
    {
        ...
        var service1 = new Service1();
        var count = service1.Service1();
        ...
    }
}

Both classes and methods are exposed thru WCF.


This should work fine, as inside Service2 you're calling Service1 in-process rather than going out over WCF (even if you were using WCF inside Service2 it should still work).

But in terms of design, this isn't very good. Service operations should be called via a service (e.g. over HTTP or TCP). If Service1 and Service2 both need access to common functionality, the solution is to refactor the common code out into a shared class or something, rather than just having it in Service1.


Is it ok? Yeah it will work. Generally, I would rather instantiate the object and call the method behind the service. It all depends on how the environment is setup though. If there are additional steps calling a service handles like logging the request etc, and you want to track that, then by all means call the service.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号