views:

302

answers:

1

Is it an acceptable programming practice to add a Service Reference to a Project where the Service being referenced is defined within the same VS Project? (Service and Service Reference are in the same Project)

example:

MyWebAppProj
-Services
--MyService
-Service References
--MyServiceServiceReference.MyServiceClient
-Default.aspx.cs uses MyServiceServiceReference.MyServiceClient

The rational behind this is that a Silverlight App may be added to the Project. If it is, we would have to expose all the Business Logic methods through a service layer, so why not just do that first and use them everywhere to stay standardized between web pages and Silverlight pages.

+3  A: 

I can't see why you would want to do that at all.

If you're already inside the same project as the service, at the very least you've already got access to all the service/data contracts, so really, calling the service is already very, very easy. You can either use a ChannelFactory directly, or write your own custom ClientBase<T>-derived client proxy class (which is trivial), there's no reason why you'd want to add service reference in this case.

Furthermore, if you added a service reference, you'd then be stuck with a bunch of duplicate definitions in the same project, which makes little sense (yes, you can isolate the generated code into a separate namespace, but still).

tomasr
Agreed. I thought I was making this too complicated. But would a ChannelFactory or ClientBase even be necessary? Could I just do something like this in Default.aspx.cs: MyService serv = new MyService(); serv.DoSomething();Even though I could just perform the same operation as the DoSomething() method right within the Default.aspx.cs code, I'd still want to do this to keep the code standardized between SL and ASP.NET.
Aaron Hoffman
If the service class doesn't really require any WCF infrastructure (like if it accesses OperationContext or something), then yes, you can very much just instantiate directly and call it. Much better.
tomasr

related questions