0

Building a stand alone WPF application that uses a MSSQL backend. I would like to structure it so it can later be converted to a client server via WCF. There are a set of classes that are shared by both the client and server. How can I structure this so the server parts can later be moved to a true server via WCF and keep the individual classes whole (or as whole as possible). Right now I have the business and data layer in single .CS with a single server class and a single a client class and set of shared classes. I get the feeling it should be three .CS but not sure.

paparazzo
  • 44,497
  • 23
  • 105
  • 176

1 Answers1

0

Since I received no responses I built a test WCF application to try and answer myself.

Clearly I am new to WCF.

With WCF between the client and the server are ServiceContracts and DataContracts. These are defined on the server side. The client discovers these contracts and they exposed as types.

A ServiceContract is a method. A DataContract is a class with just properties (OK it can do more this is just a simplification).

So in answer to my question.

Create a class with methods that represents the server side.

Create some simple classes with just public properties to represent the DataContacts.

For input to and from the methods that represents the server side only pass these simple classes.

Use these simple classes as input to the constructor for your working client classes.

The litmus test is that none of the client classes connect to SQL.

In the stand along app have some cases where we let the client class connect to SQL where have a loop and hold a connection but leave note that needs to be re factored for WCF. I know I will get some security comments here. Right now the client is hosted in Citrix and port 1433 is not open to the public. The idea is to position the product to drop Citrix.

The server methods are exposed interfaces so you can update the implementation without changing the contract.

DataContract will support inheritance.
DataContractInheritance

If someone has a better answer I would be happy to accept it.

Community
  • 1
  • 1
paparazzo
  • 44,497
  • 23
  • 105
  • 176