原来WCF中方法是可以重载的,而我之前很长一段时间以为不可以的,落后就是先从无知开始的……
文章中客户端和服务端的接口类用到了不同的类名,我调试总有问题,自己才疏学浅,搞不定,只好把不需要的Demo删掉,只剩下最简单的那个Demo,竟然成功了。索性把最简单的那个实现写出来吧。
(实例使用 Artech老师的)
步骤一:
编写服务端的接口程序:
namespace
Artech.OverloadableContract.Service
{
[ServiceContract]
public interface ICalculator
{
[OperationContract(Name = " AddWithTwoOperands " )]
double Add( double x, double y);
[OperationContract(Name = " AddWithThreeOperands " )]
double Add( double x, double y, double z);
}
}
步骤二:{
[ServiceContract]
public interface ICalculator
{
[OperationContract(Name = " AddWithTwoOperands " )]
double Add( double x, double y);
[OperationContract(Name = " AddWithThreeOperands " )]
double Add( double x, double y, double z);
}
}
编写客户端接口类:
namespace
Artech.OverloadableContract.Client
{
[ServiceContract]
public interface ICalculator
{
[OperationContract(Name = " AddWithTwoOperands " )]
double Add( double x, double y);
[OperationContract(Name = " AddWithThreeOperands " )]
double Add( double x, double y, double z);
}
}
{
[ServiceContract]
public interface ICalculator
{
[OperationContract(Name = " AddWithTwoOperands " )]
double Add( double x, double y);
[OperationContract(Name = " AddWithThreeOperands " )]
double Add( double x, double y, double z);
}
}
其他的就和不使用重载的类似了。
相关文章请参考: [原创]我的WCF之旅(1):创建一个简单的WCF程序