如何通过对Web方法可选参数? [英] How to pass optional parameters for web method?

查看:135
本文介绍了如何通过对Web方法可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个参数的Web方法。该网站的方法仅依赖于2场,其余都是可选的。

  [OperationContract的]
    公共字符串WarehouseContactInformation(INT WAID(必需),字符串CN(必需),字符串CT(可选),字符串CC(可选),字符串CFN(可选),字符串CD(可选),字符串CE(可选),字符串CW(可选))

如何,我宣布这些参数作为可选的,所以,当我调用Web方法我只有通过我有,例如值的字段:

  WarehouseContactInformation(1,'比尔','​​00012311')
WarehouseContactInformation(1,'比尔','​​00012311','12415415','123525')


解决方案

您不能。 Web方法不支持可选参数。当您为Web方法生成PROXI,您获得特定的签名,根据您的客户端和服务器交换会的消息。但它不能传递可选参数。您可以在服务器端使用默认参数,但没有可选的。

I have a web method with multiple parameters. The web method is only dependent on 2 fields, the rest are all optional.

   [OperationContract]
    public string WarehouseContactInformation(int WAID (Required), string CN (Required), string CT (Optional), string CC (Optional), string CFN (Optional), string CD (Optional), string CE (Optional),string CW (Optional))

How to I declare these parameters as optional so that when I call the Web Method I only have to pass through the fields that i have values for, example:

WarehouseContactInformation(1,'Bill','00012311')
WarehouseContactInformation(1,'Bill','00012311','12415415','123525')

解决方案

You can't. Web methods doesn't support optional parameters. When you generate proxi for web method, you make get the specific signature, according to which you client and server would exchange the messages. But it can't pass the optional parameters. You can use default parameters on the server side, but no optional.

这篇关于如何通过对Web方法可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆