A: 

I used web services software factory and liked its structure.

The structure in their sample code was something like this:

BYA.Mfg.SCM.Svc.WCF
  Source
    Business Logic
      BYA.Mfg.SCM.Svc.WCF.BusinessEntities
      BYA.Mfg.SCM.Svc.WCF.BusinessLogic
    Resource Access
      BYA.Mfg.SCM.Svc.WCF.DataAccess
    Service Interface
      BYA.Mfg.SCM.Svc.WCF.DataContracts
      BYA.Mfg.SCM.Svc.WCF.FaultContracts
      BYA.Mfg.SCM.Svc.WCF.MessageContracts
      BYA.Mfg.SCM.Svc.WCF.ServiceContracts
      BYA.Mfg.SCM.Svc.WCF.ServiceImplementation
  Tests
CodeToGlory
A: 

This may be unanswer for a number of reasons, but I'd guess the broadness of the question would have a lot to do with it. Also, its a little challenging to analyze designs with little context. There are also a lot of questions here, making an answer complicated.

First, you mentioned several classes that are not in your example code. I'll assume that Customer refers to CustomerService and likewise for the other mentioned classes and examples?

You asked if there was a better way to instatiate. You may want to look up Design Patterns like the "FlyWeight" pattern and the "Factory" pattern to help you in this. I mention "FlyWeight" because you talked about performance.

The Design Patterns book will help you. Also, Refactoring by Martin Fowler (although written in Java) will help a great deal.

fooMonster
fooMonster. Thanks for you help, you were correct, I was providing to much information in the example.I have editted the question, if you get another chance to look it over i'd appreciate it.Thanks, Steven
stevenrosscampbell
A: 

I don't know that this is the best (or even recommended) directory structure, but it's what I've settled on for now.

.\MyProject
|----\bin
|----\MyProject                                 (main application)
|----\MyProject.Core                            (shared libraries)
|----\MyProject.Server                          (WCF-hosting Windows service)
|----\MyProject.Services                        (the WCF services)
|---------\MyProject.Services.Service1          (WCF Service1)
|---------\MyProject.Services.Service1.Support  (WCF Service1-specific libraries)
|---------\MyProject.Services.Service2          (WCF Service2)
|---------\MyProject.Services.Service2.Support  (WCF Service2-specific libraries)

Based on this directory structure and what you've shown so far, the Service class would go in a MyProject.Services.Service folder under the MyProject.Services directory. The CustomerService class would go in a MyProject.Services.Service.Support folder under the MyProject.Services directory.

I've not worked with databases enough to understand the trade-offs between opening multiple simultaneous connections or simply reusing the same connection over and over. My guess is that the way you are doing it is the preferred solution.

And given that you defer your processing to the database each time your WCF service is called (by creating a new CustomerService object), you might benefit from making your WCF service a singleton. In general, WCF singletons are frowned upon for scalability reasons because the assumption is that they share state between various service calls and thus have to be synchronized. However, as shown, your WCF service does not maintain any state directly. It simply accesses the database to create, update, delete, or fetch the Customer. As long as the database access using the appropriate locking scheme, you can avoid the overhead associated with per-call instantiations of your WCF service. To make your service a singleton, use the following attribute on your service:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Service : IService
{
}
Matt Davis