简体   繁体   English

WCF代理中的可选参数

[英]Optional parameters in WCF proxy

In the following method, where last parameter is an optional parameter, which works through standard access of the binary. 在以下方法中,last参数是可选参数,它通过对二进制文件的标准访问来工作。 However in the WCF proxy it becomes mandatory, I cannot avoid, is there something that needs to be done to make it optional for the WCF proxy too. 但是,在WCF代理中,它是强制性的,我无法避免,是否需要做一些事情以使其对于WCF代理也是可选的。 Current search suggest that it might not be possible to do so, just keeping my fingers crossed to find a workaround. 当前的搜索表明可能无法做到这一点,只是让我的手指不停地寻找解决方法。

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

Although it's optional "on the wire" once the data has been serialized to XML, you cannot set default values and you cannot have default values in the code proxies. 尽管一旦将数据序列化为XML,它是可选的“在线”,但是您不能设置默认值,并且代码代理中也不能具有默认值。 You could write another wrapper around your code proxy, that looks whatever you want though. 您可以在代码代理周围编写另一个包装器,尽管看起来您想要什么。

I think there are two solutions: 我认为有两种解决方案:

1-you may create two methods one with optional parameter. 1-您可以创建两个方法,其中一个带有可选参数。

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

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

2-you may create a DTO representing your parameters and assign a default value in the DTO. 2-您可以创建一个代表您的参数的DTO,并在DTO中分配一个默认值。

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

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