【问题标题】:Interface and Datastructure design for WCFWCF的接口和数据结构设计
【发布时间】:2012-09-07 07:35:22
【问题描述】:

我留下了一个使用远程处理的旧代码。我需要将此代码升级到 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的实体接口和数据结构设计策略有什么好的建议吗?

【问题讨论】:

    标签: c# .net wcf interface


    【解决方案1】:

    看看这篇文章:

    Writing Highly Maintainable WCF Services

    本文讨论了在SOLIDly 基于commandsqueries 设计的架构模式之上将WCF 服务编写为真正的薄层。在使用这种命令/查询风格的编程时,WCF 服务可以定义为非常小的基础架构代码,即使添加了新操作也无需更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多