C# 服务接口-几种方法的比较

C# 服务接口-几种方法的比较,c#,.net,soa,C#,.net,Soa,我很难决定哪种方法更好: interface IService { ISomething CreateSomething(); } interface ISomething { void Do(string parameter); } vs vs vs 与任何其他 IService接口应该以多种不同的方式使用: 作为类库 作为WCF服务 作为XML服务 作为JSON服务 ISomething可能有许多客户机想要调查的属性,以及它可能执行的许多操作ISomething只是我需要以这

我很难决定哪种方法更好:

interface IService {
  ISomething CreateSomething();
}

interface ISomething {
  void Do(string parameter);
}
vs

vs

vs

与任何其他

IService
接口应该以多种不同的方式使用:

  • 作为类库
  • 作为WCF服务
  • 作为XML服务
  • 作为JSON服务
ISomething
可能有许多客户机想要调查的属性,以及它可能执行的许多操作<代码>ISomething只是我需要以这种方式公开的十几个类中的一个<代码>ISomething可能会返回更多我可以在其上执行操作的接口

我将感谢您的建议和想法

编辑:

其想法是创建一个服务,允许用户构建工作流图,并支持设计器。我的要求是拥有支持客户机任何风格的服务代码(因此
int
参数方法)。同时,我不想遇到类型和方法的爆炸


也许最好的方法是将它设计成一个功能丰富的.NET库,并为任何可能使用它的频道创建facades(?)

我看到的问题是,您希望一个类同时成为一个服务和数据契约
ISomething
不能是接口,因为您实际上传递了具体类型,并且您的客户机应该知道它们的结构。所以我的建议是服务仍然是服务,数据契约仍然是它自己

class Something
{
}

interface IService {  
  void Do(string parameter);
  Something GetSomething();
}

class SomeService : IService {
  private Something smth;  

  public void SomeService()
  {
    smth = CreateSomething();
  }

  public void Do()
  {
    //
  }

  public Something GetSomething()
  {
    return smth;
  }
}

我看到的问题是,您希望类同时成为服务和数据契约
ISomething
不能是接口,因为您实际上传递了具体类型,并且您的客户机应该知道它们的结构。所以我的建议是服务仍然是服务,数据契约仍然是它自己

class Something
{
}

interface IService {  
  void Do(string parameter);
  Something GetSomething();
}

class SomeService : IService {
  private Something smth;  

  public void SomeService()
  {
    smth = CreateSomething();
  }

  public void Do()
  {
    //
  }

  public Something GetSomething()
  {
    return smth;
  }
}
我将使用:

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}
我想它会产生最少的流量,因为如果你只是从
CreateSomething
返回ID,如果你需要处理详细信息,你很可能会进行另一次旅行

使用
DoSomething
中的id可以提供最少的通信量,因为整个对象似乎不需要

始终尝试设计服务接口,以便您必须使用尽可能多的调用来完成所需的操作。这也意味着很难告诉你答案,因为我不知道目的。

我会使用:

interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}
我想它会产生最少的流量,因为如果你只是从
CreateSomething
返回ID,如果你需要处理详细信息,你很可能会进行另一次旅行

使用
DoSomething
中的id可以提供最少的通信量,因为整个对象似乎不需要


始终尝试设计服务接口,以便您必须使用尽可能多的调用来完成所需的操作。这也意味着很难告诉您答案,因为我不知道预期目的。

选项1对我来说似乎是最好的。“做”某件事似乎是一件事的操作,而不是iSeries设备的操作;我们不知道您的需求、业务逻辑等。一般的答案是:做适合您并符合您需求的事情。选项1对我来说似乎是最好的。“做”某件事似乎是一件事的操作,而不是iSeries设备的操作;我们不知道您的需求、业务逻辑等。一般的答案是:做适合您并符合您需求的事情。如果在类库中使用,这是很难看的。但是我同意你所说的一切,所以问题是需求不是太笼统了。如果在类库中使用它,那就很难看了。但是我同意你所说的一切,所以问题是需求不是太笼统。是的,因为可能涉及到不止一个
isomathing
实例。是的,因为可能涉及到不止一个
isomathing
实例。
interface IService {
  ISomething CreateSomething();
  void DoSomething(int somethingId, string parameter)
}