我留下了一个使用远程处理的旧代码。我需要将此代码升级到WCF。
坦率地说,我坚持如何重新设计客户端和接口的接口。服务器用于通信。它看起来像这样:
public interface IDDCEngine
{
ReadDiagnosticEntirePointValuesResponse ReadDiagnosticEntirePointValues(string host);
GetEntirePointListResponse GetEntirePointList(string host);
SetSerialPortListResponse SetSerialPointList(string host, SetSerialPortList serialPortList);
SetNationalListResponse SetNationalList(string host, SetNationalList nationalList, int count);
SetModbusListResponse SetModbusList(string host, SetModbusList modbusList, int count);
SetIOPointListResponse SetIOPointList(string host, SetIOPoint pointList, int count);
GetIOPointResponse GetIOPointList(string host);
SetLogicListResponse SetLogicList(string host, SetLogicList logicList, int count);
GetDDCVersionResponse GetDDCVersion(string host);
GetDDCUptimeResponse GetDDCUptime(string host);
GetDDCCPUMemoryStatusResponse GetDDCCPUMemoryStatus(string host, int count);
...about 20 more interfaces
}
请求/响应的类:
[Serializable]
public class SetIOPoint
{
public string[] pointidentifier;
public string[] pointname;
public string[] pointaddress;
public string[] pointtype;
public string[] devicetype;
public string[] description;
public string[] backup;
public string[] relinquishdefault;
public string[] unit;
public string[] minpresvalue;
public string[] maxpresvalue;
public string[] correctvalue;
public string[] covenable;
public string[] covincrement;
public string[] covtarget;
public string[] covlifetime;
public string[] historyenable;
public string[] historyincrement;
public string[] alarmenable;
public string[] highlimit;
public string[] lowlimit;
public string[] polarity;
public string[] inactivetext;
public string[] activetext;
public string[] feedbackenable;
public string[] feedbacktime;
public string[] numofstates;
public string[] statetext;
}
[Serializable]
public class GetIOPointResponse
{
public string[] pointidentifier;
public string[] pointname;
public string[] pointaddress;
public string[] pointtype;
public string[] devicetype;
public string[] description;
public string[] backup;
public string[] relinquishdefault;
public string[] unit;
public string[] minpresvalue;
public string[] maxpresvalue;
public string[] correctvalue;
public string[] covenable;
public string[] covincrement;
public string[] covtarget;
public string[] covlifetime;
public string[] historyenable;
public string[] historyincrement;
public string[] alarmenable;
public string[] highlimit;
public string[] lowlimit;
public string[] polarity;
public string[] inactivetext;
public string[] activetext;
public string[] feedbackenable;
public string[] feedbacktime;
public string[] numofstates;
public string[] statetext;
}
[Serializable]
public class RequestDDCRebootResponse
{
public string result;
}
[Serializable]
public class GetDDCCurrenttimeResponse
{
public string result;
}
[Serializable]
public class StartDDCBackupResponse
{
public string result;
}
[Serializable]
public class EndDDCBackupResponse
{
public string result;
}
[Serializable]
public class StartDDCRestoreResponse
{
public string result;
}
[Serializable]
public class EndDDCRestoreResponse
{
public string result;
}
...List goes ON
编写的界面和数据结构非常糟糕。我想重写接口和数据结构,这样我就不必定义数百万个操作合同。
对于WCF的固体接口和数据结构设计策略有什么好的建议吗?
答案 0 :(得分:1)
看一下这篇文章:
Writing Highly Maintainable WCF Services
本文讨论在基于SOLIDly和commands的queries设计架构模式之上编写WCF服务作为真正的瘦层。使用此命令/查询样式的编程时,即使添加了新操作,也可以将WCF服务定义为一小段基础架构代码,不需要更改。