0

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

4

1 回答 1

1

看看这篇文章:

编写高度可维护的 WCF 服务

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

于 2012-09-14T07:06:48.740 回答