繁体   English   中英

WCF代理中的可选参数

[英]Optional parameters in WCF proxy

在以下方法中,last参数是可选参数,它通过对二进制文件的标准访问来工作。 但是,在WCF代理中,它是强制性的,我无法避免,是否需要做一些事情以使其对于WCF代理也是可选的。 当前的搜索表明可能无法做到这一点,只是让我的手指不停地寻找解决方法。

public UnifiedDTO GetAllCardTitle(string trainSymbolOrCarLocation, 
                                           DateTime startDate, 
                                           DateTime endDate, 
                                           string procedureName = CardTitle.procedureNameTrainRuns)

尽管一旦将数据序列化为XML,它是可选的“在线”,但是您不能设置默认值,并且代码代理中也不能具有默认值。 您可以在代码代理周围编写另一个包装器,尽管看起来您想要什么。

我认为有两种解决方案:

1-您可以创建两个方法,其中一个带有可选参数。

public UnifiedDTO GetAllCardTitle(string trainSymbolOrCarLocation, 
                                           DateTime startDate, 
                                           DateTime endDate)

public UnifiedDTO GetAllCardTitle(string trainSymbolOrCarLocation, 
                                           DateTime startDate, 
                                           DateTime endDate, 
                                           string procedureName)

2-您可以创建一个代表您的参数的DTO,并在DTO中分配一个默认值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM