本文介绍了为WCF实现一个接口时,不能使用可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的界面我宣布这一点。

  [OperationContract的] 
[WebGet]
字符串GetStuff(字符串蜂鸣声,弦乐BOOP =懒得打字);



我实现它,如下所示。

 字符串GetStuff(字符串蜂鸣声,弦乐BOOP =懒得打字){...} 

据编译和上传我的WCF服务。然而,当我用它作为一个Web引用,并尝试下面的执行代码,我得到的编译器直叫,哭泣有关与单个参数的签名都没法。最后一行就是问题所在。



我怎么能那么是的懒得打字默认

  ServiceClient客户端=新ServiceClient(); 
client.GetStuff(blobb,不偷懒);
client.GetStuff(blobb);


解决方案

简单:缺省参数不被支持。



在设计和原因。我们使用C#写WCF的合同,但这是一个符号上的把戏。并不是每一个C#语言的功能可以在SOAP,REST或JSON来实现。


In my interface I have declared this.

[OperationContract]
[WebGet]
String GetStuff(String beep, String boop = "too lazy to type");

I implemented it as follows.

String GetStuff(String beep, String boop = "too lazy to type") { ... }

It compiles and uploads as my WCF service. However, when I used it as a web reference and try to execute the code below, I get the compiler whining and weeping about no method with signature of a single parameter. The last line is the problem.

How can I then be too lazy to type by default?

ServiceClient client = new ServiceClient();
client.GetStuff("blobb", "not lazy");
client.GetStuff("blobb");
解决方案

Simply: default arguments are not supported.

By design and with reason. We use C# to write WCF contracts but that's a notational trick. Not every C# language feature can be implemented in SOAP, REST or JSon.

这篇关于为WCF实现一个接口时,不能使用可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 23:53