为WCF实现一个接口时,不能使用可选参数

编程入门 行业动态 更新时间:2024-10-26 23:39:05
本文介绍了为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实现一个接口时,不能使用可选参数

本文发布于:2023-06-08 03:50:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/576129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可选   接口   参数   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!