我有一个使用.NET Remoting建立与客户端的连接的服务器端代码。通常情况下,我知道使用接口与客户端和服务器之间传递的对象是常态,并且是一个更安全的选择,但对于我正在建立的简单通信,我不认为需要经历定义必要的类和接口。NET Remoting约定
因此,对于下面的代码,由于我只是向客户端返回一个字符串,我不觉得必要,但有些人可能会说,否则我在这里发布我的问题。我应该遵循一般惯例还是坚持我的方式?下面显示的代码是以远程方式建立服务器的正确方法吗?
(不要问为什么我使用的,而不是WCF远程处理。我的老板明确要求远程处理,我不知道为什么。)
class HttpServer
{
[STAThread]
public static Boolean startService()
{
HttpChannel channel = new HttpChannel(80);
ChannelServices.RegisterChannel(channel);
Type ddcServerType = Type.GetType("DDCEngine.DDCServer");
RemotingConfiguration.RegisterWellKnownServiceType(ddcServerType, "DDCServer", WellKnownObjectMode.Singleton);
return true;
}
}
public class DDCServer : MarshalByRefObject
{
public string Hello()
{
string r = "hello";
return r;
}
[Description("Sets a new IO Point List in the DDC.")]
public string SetIOPointList(string host, DDCService.pointInformation[] pointList)
{
string result;
DDCService.LGeDDCClient ddc = new DDCService.LGeDDCClient("LGeDDC", host);
try
{
result = ddc.SetIOPoint(pointList);
}
catch (Exception ex)
{
result = ex.ToString();
}
return result;
}
我想这很好,这很简单,但你有一个平均的老板。考虑未来的变化以及有什么机会来扩展这一点。那么你最好从一开始就做好。 –