简体   繁体   中英

How to define optional parameters for a method using XML-RPC.NET

I'm developing a XML-RPC service in C# using the XML-RPC.NET library . The service will be used to expose a forum to Tapatalk users

The Tapatalk API documentation states which methods should be implemented. Sometimes a parameter is specified as optional.

Eg get_topic has 4 parameters: forum_id , start_num , last_num and mode

The method is invoked by the Tapatalk app with either all parameters or only the first 3 (so mode is omitted).

I defined the methods as follows:

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

When the method is invoked with all 4 parameters specified all goes well. When mode is omitted I get the following error: Request contains too few param elements based on method signature.

Specifing mode as an optional parameter doesn't seem to do the trick:

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

Trying to overload the method results in this error: 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)

Any idea how I specify a parameter as optional?

Niels

Does this help? Justing getting into the world of xml-rpc myself.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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