C# xml-rpc

发布于 2024-12-19 05:59:06 字数 390 浏览 0 评论 0原文

所以我必须使用 Web 服务(xml-rpc),我使用 xml-rpc.net 库来执行此操作。我必须传递的参数之一必须是 .net 中没有此类变量的类型。目前我只是编写 XML 并发布,这不是一个令人满意的解决方案。

日期时间的 xml 看起来如何:

</param>
<param>
  <value>
    <dateTime.iso8601>20101117T09:42:00</dateTime.iso8601>
  </value>
</param>
<param>

任何人都有任何聪明的想法,有人说创建一个类 dateTime.iso8601 的变量并将其用作参数类型。

so I have to hit a webservice (xml-rpc), im using xml-rpc.net library to do this. One of the parameters i have to pass must be of type of which there is no such thing in .net as a variable. At the moment i am just writing the XML and posting, this is not a satisfiable solution.

How the xml for the datetime looks:

</param>
<param>
  <value>
    <dateTime.iso8601>20101117T09:42:00</dateTime.iso8601>
  </value>
</param>
<param>

anyone got any smart ideas, someone said make a variable of a class dateTime.iso8601 and use that as the parameter type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2024-12-26 05:59:07

xml-rpc.net 当然需要 System.Datetime 并转换为 dateTime.iso8601。我遇到的一个问题是 dateTime.iso8601 的各种解释。从您的 xml 模板中,支持您的日期时间输出 (20101117T09:42:00),并且您不会遇到相同的问题。我有一个非常严格的上游服务器,需要一些偏移量(例如+001),并且我必须扩展日期时间格式并将其传递到 xml-rpc.net。

编辑

是的,我修改了代码以实现新的 DateTimeFormat。我下载了源代码并进行了以下修改(我希望它能更好地托管并且可以提供修改)。

有一个 XmlRpcSerializer.cs,这是将类型序列化为 xml-rpc 格式的地方。您需要的方法自然是...

void Serialize(
      XmlWriter xtw,
      Object o,
      MappingActions mappingActions,
      List<object> nestedObjs)

此方法中的某个位置是对 XmlRpcType.tDateTime 的检查:

else if (xType == XmlRpcType.tDateTime)
        {
          DateTime dt = (DateTime)o;
          //The following line is what you need, if a custom DateTime format was supplied, to override the default
          string sdt = dt.ToString((string.IsNullOrEmpty(DateTimeFormat) ? "yyyyMMdd'T'HH':'mm':'ss" : DateTimeFormat),
          DateTimeFormatInfo.InvariantInfo);
          WriteFullElementString(xtw, "dateTime.iso8601", sdt);
        }

故事的其余部分是如何将自定义日期时间格式传递给 XmlRpcSerializer 类。您只需向此类添加一个属性即可实现此目的。有一个可以使用的 XmlRpcFormatSettings,但这取决于您。

xml-rpc.net certainly takes a System.Datetime and converts to dateTime.iso8601. A gotcha I had was with the various interpretations of dateTime.iso8601. From your xml template, your datetime output is supported (20101117T09:42:00) and you won't have the same problem. I had a very strict upstream server that wanted some offset (e.g +001) and I had to extend and pass a datetime format to xml-rpc.net.

Edit

Yea I modified the code to achieve the new DateTimeFormat. I downloaded the source and made the following modifications (I wish it was better hosted and one could offer a modification).

There is an XmlRpcSerializer.cs, which is where the serialization of the type to xml-rpc format happens. The method you need is naturally...

void Serialize(
      XmlWriter xtw,
      Object o,
      MappingActions mappingActions,
      List<object> nestedObjs)

Somewhere in this method, is a check for XmlRpcType.tDateTime:

else if (xType == XmlRpcType.tDateTime)
        {
          DateTime dt = (DateTime)o;
          //The following line is what you need, if a custom DateTime format was supplied, to override the default
          string sdt = dt.ToString((string.IsNullOrEmpty(DateTimeFormat) ? "yyyyMMdd'T'HH':'mm':'ss" : DateTimeFormat),
          DateTimeFormatInfo.InvariantInfo);
          WriteFullElementString(xtw, "dateTime.iso8601", sdt);
        }

The rest of the story is how to pass the custom datetime format to the XmlRpcSerializer class. You could just add a property to this class to make it happen. There is an XmlRpcFormatSettings that could be used but that's up to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文