通过WCF模拟重载方法的最佳做法是什么?WCF“重载”方法的最佳做法
通常我会写这样
interface IInterface
{
MyType ReadMyType(int id);
IEnumerable<MyType> ReadMyType(String name);
IEnumerable<MyType> ReadMyType(String name, int maxResults);
}
的界面会是什么这个接口的样子后你转换它WCF?
通过WCF模拟重载方法的最佳做法是什么?WCF“重载”方法的最佳做法
通常我会写这样
interface IInterface
{
MyType ReadMyType(int id);
IEnumerable<MyType> ReadMyType(String name);
IEnumerable<MyType> ReadMyType(String name, int maxResults);
}
的界面会是什么这个接口的样子后你转换它WCF?
如果你喜欢,你可以留下它。只需使用OperationContract属性的name属性即可。
[ServiceContract]
interface IInterface
{
MyType ReadMyType(int id);
[OperationContract(Name= "Foo")]
IEnumerable<MyType> ReadMyType(String name);
[OperationContract(Name= "Bar")]
IEnumerable<MyType> ReadMyType(String name, int maxResults);
}
由于mwilson已经说过 - WCF不允许方法在服务定义(WSDL)中具有相同的名称。
如果在.NET中有两个或多个具有相同名称的(重载)方法,则需要通过在每个方法的[OperationContract]
属性上指定Name=
属性来为WCF服务定义消除歧义。 (或不支持.NET) - 它是一种可互操作的标准,WSDL标准目前不支持方法重载 - 每种方法都必须通过名称唯一标识。
可能的重复[为什么方法重载是不允许在WCF?](http://stackoverflow.com/questions/10276124/why-method-overloading-is-not-allowed-in-wcf) – 2015-02-02 00:52:09