.NET Web服务的最佳做法... SRP? [英] .net Web services best practice...SRP?

查看:229
本文介绍了.NET Web服务的最佳做法... SRP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么被认为是适当的发展有关的.asmx或WCF服务类有多少个文件,代码,责任等线路?大部分人都单独发布服务的.asmx文件不同的CRUD方法,每类?

What is considered the appropriate development for .asmx or wcf service classes regarding how many files, lines of code, responsibilities, etc? Do most people publish separate .asmx service files for the different crud methods for every class?

推荐答案

首先,最好的做法新的发展是使用WCF。请参见微软:ASMX Web服务是一种传统技术

First of all, the best practice for new development is to use WCF. See Microsoft: ASMX Web Services are a "Legacy Technology".

其次,在SOA中,人们试图创建coarsly细粒度运营服务。例如,你想一个OrderProduct操作,而不是StartOrder,AddLineItem,AddOption,FinishOrder操作。该OrderProduct操作如下可能接受OrderDTO:

Second, in SOA, one tries to create services with coarsly-grained operations. For instance, you would want an OrderProduct operation, rather than StartOrder, AddLineItem, AddOption, FinishOrder operations. The OrderProduct operation might accept an OrderDTO as follows:

public class OrderDTO {
    public CustomerInfo Customer {get;set;}
    public DateTime OrderTime {get;set}
    public DateTime ShipTime {get;set;}
    public List<LineItemDTO> LineItems {get; private set;}
}

public class LineItemDTO {
    public int LineItemNumber {get;set;}
    public string ProductName {get;set;}
    public int Quantity {get;set}
    public Decimal Amount {get;set}
    public Decimal ExtendedAmount {get;set;}
}

而不是仅仅是创建一个空的顺序StartOrder方法,其次是AddLineItem呼吁添加单个行项目(正如你可能从桌面应用程序一样),我推荐一个接受OrderDTO,这将有LineItemDTO集合的单个OrderProduct方法。你会一下子将整个顺序,添加所有的作品在一个事务中,并完成。

Rather than a StartOrder method that just creates an empty order, followed by AddLineItem calls to add individual line items (as you might do from a desktop application), I'm recommending a single OrderProduct method that accepts an OrderDTO, which will have a collection of LineItemDTO. You'll send the entire order all at once, add all the pieces in a transaction, and be done.

最后,我想说,你还是应该分成业务层和数据层。服务层应该只关心事物的服务方面,并为了把事情做好调用你的业务逻辑层上。

Finally, I'd say that you should still separate into business and data layers. The service layer should be concerned only with the services side of things, and will call on your business logic layer in order to get things done.

这篇关于.NET Web服务的最佳做法... SRP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆