【问题标题】:How to define optional parameters for a method using XML-RPC.NET如何使用 XML-RPC.NET 为方法定义可选参数
【发布时间】:2014-02-28 05:39:10
【问题描述】:

我正在使用XML-RPC.NET library 在 C# 中开发 XML-RPC 服务。该服务将用于向 Tapatalk 用户公开论坛

Tapatalk API 文档说明了应该实现哪些方法。有时一个参数被指定为可选的。

例如get_topic 有 4 个参数:forum_idstart_numlast_nummode

该方法由 Tapatalk 应用程序使用所有参数或仅前 3 个参数调用(因此 mode 被省略)。

我定义的方法如下:

[XmlRpcMethod("get_topic"]
public GetTopicResult GetTopic(string forum_id, int? start_num, int? last_num, string mode)
    

当使用指定的所有 4 个参数调用该方法时,一切顺利。当mode 被省略时,我得到以下错误:Request contains too few param elements based on method signature.

将模式指定为可选参数似乎不起作用:

[XmlRpcMethod("get_topic"]
public GetTopicResult GetTopic(string forum_id, int? start_num, int? last_num, string mode = "")

试图重载方法会导致这个错误:Method GetTopic in type Mobiquo has duplicate XmlRpc method name get_topic

[XmlRpcMethod("get_topic"]
public GetTopicResult GetTopic(string forum_id, int? start_num, int? last_num)

[XmlRpcMethod("get_topic"]
public GetTopicResult GetTopic(string forum_id, int? start_num, int? last_num, string mode)

知道如何将参数指定为可选参数吗?

尼尔斯

【问题讨论】:

    标签: c# xml-rpc xml-rpc.net


    【解决方案1】:

    这有帮助吗?自己刚刚进入 xml-rpc 的世界。

    http://xml-rpc.net/faq/xmlrpcnetfaq-3-0-0.html#1.15

    【讨论】:

    • 我首先查看了常见问题解答,但这是用于响应结构的参数的可选映射(如果我理解正确的话)。
    猜你喜欢
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2013-03-25
    • 2019-03-08
    相关资源
    最近更新 更多