I am working on a server-client app in c# and need to send an object from the client to the server via WCF. For simplicity I will call it WorkingClass as it is what does the work.
public class WorkingClass
{
public WorkingClass (FileInfo uncompressedFile, FileInfo compressedFile)
{
UncompressedFile = uncompressedFile;
CompressedFile = compressedFile;
}
public FileInfo UncompressedFile { get; private set; }
public FileInfo CompressedFile { get; private set; }
public void ZipFile()
{
//zip file
}
}
Now I need to send it to the server via WCF. I don't need the whole WorkingClass FileInfo properties serialized and sent, so I have a simple class which I will call MessageClass that has simple strings.
public class MessageClass
{
public MessageClass(string uncompressedFileName, string compressedFileName)
{
UncompressedFileName = uncompressedFileName;
CompressedFileName = compressedFileName;
}
public string UncompressedFileName { get; private set; }
public string CompressedFileName { get; private set; }
}
I can add a ToMessage() instance method and a FromMessage static method to the WorkingClass. Or instead of the static FromMessage method, I could add a constructor to the WorkingClass that accepts a MessageClass as a parameter. To me these options seem to tie both classes tightly together and the WorkingClass should only have to worry about zipping a file, not converting itself for communication via WCF. Do I maybe create a converter class?
The Server will then need to convert from the message to its own working class.
Am I on the right path to handle this sort of thing? Is there a best practice or design pattern I can follow?