最近玩wordpress,利用xml-rpc写发布程序时,发现了两个好用的工具库:
xml-rpc.net:实现了xml-rpc的.net框架;
Joe Blogs:封装了wordpress api的.net库;
开发过程中发现,使用Joe Blogs发布博客时无法设置分类,对比live writer 发布博客时http包发现,wordpress设置分类使用的分类名,而不是分类Id;
OK,找到原因后,修改Joe Blogs源码:
1. 类 JoeBlogs.Post 修改为
using System;
namespace JoeBlogs
{
public class Post
{
private int _postID;
public Post()
{
DateCreated = DateTime
.Now;
}
public int PostID { get { return _postID; } }
public DateTime DateCreated { get; set; }
public string Body { get; set; }
public string Title { get; set; }
//public int[] Categories { get; set; }
public string[] Categories { get; set; }
public string[] Tags { get; set; }
public override string ToString()
{
return this.Body;
}
}
}
2. 结构体 JoeBlogs.XmlRpc.XmlRpcPost 修改为
using System;
using CookComputing.XmlRpc;
namespace JoeBlogs.XmlRpc
{
/// <summary>
/// This struct represents the information about a post that could be returned by the
/// EditPost(), GetRecentPosts() and GetPost() methods.
/// </summary>
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct XmlRpcPost
{
public DateTime dateCreated;
public string description;
public string title;
public string postid;
//public int[] categories;
public string[] categories;
public string[] mt_keywords;
public override string ToString()
{
return this.description;
}
}
}
3. 创建文章时,将分类名传给文章的分类
Post post = new Post();
post.Title = title;
post.Body = body;
post.Categories = new string[] { category.Name };
一切搞定!
我在codeplex上发现也有人碰到相同问题,回复了解决方法,项目发起者说他已将项目转移到github project