views:

48

answers:

2

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.

+1  A: 

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.

Kevin
+1  A: 

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.

Graham Clark