C# 使用 Web 服务 / WCF 的命名约定且没有过载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/698818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 13:55:43  来源:igfitidea点击:

Naming conventions with web service / WCF and no overload

c#wcfweb-servicesnaming-conventions

提问by

Currently have the task of designing a web service ( i am going to wcf but principles still apply) in c#. Problem is there is no overloading of methods which i am aware of so i need to name web methods with different names.

目前的任务是在 c# 中设计一个 web 服务(我要去 wcf 但原则仍然适用)。问题是我所知道的方法没有重载,所以我需要用不同的名称命名 Web 方法。

I would really like some input on naming conventions, there just doesn't seem to be anything out there - for example.

我真的很想对命名约定进行一些输入,例如,似乎没有任何内容。

My main method is GetMortgages() - which returns all mortgages. I need another one where it will return mortgages within a certain price range so what would you recommend for this GetMorgagesPriceRange, InPriceRange, WithPriceRange.

我的主要方法是 GetMortgages() - 它返回所有抵押贷款。我需要另一个它会在某个价格范围内返回抵押贷款,所以你会推荐这个 GetMorgagesPriceRange、InPriceRange、WithPriceRange。

I am little confused about best practices fro naming web methods, i would love to just overload GetMortgages but of course with web services i can't...

我对命名 Web 方法的最佳实践有点困惑,我很想重载 GetMortgages,但当然使用 Web 服务我不能......

So would it be better to do GetNounDesciption??

那么做GetNounDescription会更好吗??

Anyone know of any good webservices out there that has a method that is the same but each method has different parameters passed - really like to know about anything here

任何人都知道那里有任何好的 Web 服务,它们的方法是相同的,但每个方法都传递了不同的参数 - 真的很想知道这里的任何事情

If it get practice to start my webmethod with GET if it is something that returns something??

如果可以练习使用 GET 启动我的 webmethod,如果它返回某些东西?

What about something that saves and sends something, is there a standard here?? i.e. PUT or SAVE ???

什么东西存东西送东西,这里有标准吗??即放置或保存???

There must be some kind of book of rule to follow??

必须有某种规则书可以遵循?

Really would like some input is anyone has any

真的想要一些输入是任何人有任何

Thank you Mark

谢谢马克

回答by Tom Anderson

There really isn't any "rule book" for naming conventions. You find one that works for you.

命名约定确实没有任何“规则手册”。你会找到一个适合你的。

The most common adoption with .Net is to follow the Microsoft .Net naming conventions, and with Web Services, just treat them as an extension of your assembly, not as a special case.

.Net 最常见的采用是遵循 Microsoft .Net 命名约定,而对于 Web 服务,只需将它们视为程序集的扩展,而不是特殊情况。

http://msdn.microsoft.com/en-us/library/ms229045.aspx

http://msdn.microsoft.com/en-us/library/ms229045.aspx

So, GetMortgages(), GetMortgagesInPriceRange(startPrice,endPrice), etc... is fine.

因此,GetMortgages()、GetMortgagesInPriceRange(startPrice,endPrice) 等……很好。

As far as "saving", a lot of people will use the "SubmitNoun".

至于“保存”,很多人都会用“SubmitNoun”。

回答by John Saunders

I think you're doing fine. Describe them based on what it is they're doing. GetAllMortgages(), GetMortgagesInPriceRange(), etc.

我觉得你做得很好。根据他们正在做什么来描述他们。GetAllMortgages()、GetMortgagesInPriceRange() 等。

Take into consideration any domain-specific terminology. For instance, if the mortgage-industry term for a price range of a mortgage had been "Demographic", then GetMortgagesForDemographic would be the better name, even if you know that the only "demographic" features are the price range.

考虑任何特定于领域的术语。例如,如果抵押贷款价格范围的抵押贷款行业术语是“人口统计”,那么 GetMortgagesForDemographic 将是更好的名称,即使您知道唯一的“人口统计”特征是价格范围。

回答by Krzysztof Kozmic

You could go with repository-pattern if you have repository-like service (as I assume by your examples you have) convention

如果您有类似存储库的服务(正如我在您的示例中假设的那样)约定,您可以使用存储库模式

GetXByY(params)

回答by Krzysztof Kozmic

Also, you should probably avoid overloading web service methods. Use distinct method names.

此外,您可能应该避免重载 Web 服务方法。使用不同的方法名称。

回答by Krzysztof Kozmic

You could also have the GetMortgages() service method take a 'document' instead of parameters and design the optional filter criteria in the document. That way you have only one method that handles all 'overloads'.

您还可以让 GetMortgages() 服务方法采用“文档”而不是参数,并在文档中设计可选的过滤条件。这样你就只有一种方法来处理所有的“重载”。

<GetMortgages>
  <filter> .... </filter>
  <sort> .... </sort>
  <group> .... </group>
</GetMortgages>