今天简单的研究了一下xml-rpc,做了一个小demo,使得最近开发的一个blog系统可以试用word2007来发表文章,现在还没有具体的实现,只是试Word能识别我写的Api.
MetaWeblogService.cs
using
System;
using System.Collections.Generic;
using System.Text;
using CookComputing.MetaWeblog;
using CookComputing.XmlRpc;
using CookComputing.Blogger;
namespace BusiDao.MetaWeblog
{
public class MetaWeblogService : XmlRpcService
{
[XmlRpcMethod("blogger.getUsersBlogs", Description = "获取博客信息")]
public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
{
BlogInfo[] infoarr = new BlogInfo[1];
for (int i = 0; i < 1; i++)
{
infoarr[i].url = string.Format("http://{0}.html", i);
infoarr[i].blogName = string.Format("测试 {0}", i);
infoarr[i].blogid = i.ToString();
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getCategories", Description = "获取分类列表")]
public CategoryInfo[] getCategories(string blogid, string username, string password)
{
CategoryInfo[] infoarr = new CategoryInfo[5];
for (int i = 0; i < 5; i++)
{
infoarr[i].categoryid = i.ToString();
infoarr[i].description = i.ToString();
infoarr[i].htmlUrl = string.Format("http://{0}.html", i);
infoarr[i].rssUrl = string.Format("http://{0}.xml", i);
infoarr[i].title = string.Format("测试 {0}", i);
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.newPost", Description = "发表日志")]
public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
return "1";
}
[XmlRpcMethod("metaWeblog.getRecentPosts", Description = "获取日志列表")]
public CookComputing.MetaWeblog.Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
{
CookComputing.MetaWeblog.Post[] infoarr = new CookComputing.MetaWeblog.Post[20];
for (int i = 0; i < 20; i++)
{
infoarr[i].categories = new string[2] { "1", "2" };
infoarr[i].dateCreated = DateTime.Now;
infoarr[i].description = string.Format("说明 {0}", i);
Enclosure el=new Enclosure();
el.length=i;
el.type=i.ToString();
el.url=string.Format("http://{0}.html", i);
infoarr[i].enclosure = el;
infoarr[i].link = string.Format("http://{0}.html", i);
infoarr[i].mt_allow_comments = true;
infoarr[i].mt_allow_pings = true;
infoarr[i].mt_convert_breaks = true;
infoarr[i].mt_excerpt = "mt_excerpt";
infoarr[i].mt_text_more = "more 更多";
infoarr[i].permalink = "";
infoarr[i].postid = i.ToString();
Source su = new Source();
su.name = string.Format("测试 {0}", i);
su.url = string.Format("http://{0}.html", i);
infoarr[i].source = su;
infoarr[i].title = string.Format("标题 {0}", i);
infoarr[i].userid = "1";
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getPost", Description = "获取日志信息")]
public CookComputing.MetaWeblog.Post getPost(string postid, string username, string password)
{
CookComputing.MetaWeblog.Post p = new CookComputing.MetaWeblog.Post();
p.categories = new string[2] { "1", "2" };
p.dateCreated = DateTime.Now;
p.description = "说明" + postid.ToString();
Enclosure el = new Enclosure();
el.length = 1;
el.type = "2";
el.url = string.Format("http://{0}.html", 3);
p.enclosure = el;
p.link = "link";
p.mt_allow_comments = true;
p.mt_allow_pings = true;
p.mt_convert_breaks = true;
p.mt_excerpt = "mt_excerpt";
p.mt_text_more = "mt_text_more";
p.permalink = "permalink";
p.postid = postid;
Source su = new Source();
su.name = string.Format("测试 {0}", 1);
su.url = string.Format("http://{0}.html", 1);
p.source = su;
p.title = "标题" + postid;
p.userid = "1";
return p;
}
[XmlRpcMethod("metaWeblog.editPost", Description = "修改日志")]
public bool editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
return true;
}
}
}
using System.Collections.Generic;
using System.Text;
using CookComputing.MetaWeblog;
using CookComputing.XmlRpc;
using CookComputing.Blogger;
namespace BusiDao.MetaWeblog
{
public class MetaWeblogService : XmlRpcService
{
[XmlRpcMethod("blogger.getUsersBlogs", Description = "获取博客信息")]
public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
{
BlogInfo[] infoarr = new BlogInfo[1];
for (int i = 0; i < 1; i++)
{
infoarr[i].url = string.Format("http://{0}.html", i);
infoarr[i].blogName = string.Format("测试 {0}", i);
infoarr[i].blogid = i.ToString();
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getCategories", Description = "获取分类列表")]
public CategoryInfo[] getCategories(string blogid, string username, string password)
{
CategoryInfo[] infoarr = new CategoryInfo[5];
for (int i = 0; i < 5; i++)
{
infoarr[i].categoryid = i.ToString();
infoarr[i].description = i.ToString();
infoarr[i].htmlUrl = string.Format("http://{0}.html", i);
infoarr[i].rssUrl = string.Format("http://{0}.xml", i);
infoarr[i].title = string.Format("测试 {0}", i);
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.newPost", Description = "发表日志")]
public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
return "1";
}
[XmlRpcMethod("metaWeblog.getRecentPosts", Description = "获取日志列表")]
public CookComputing.MetaWeblog.Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
{
CookComputing.MetaWeblog.Post[] infoarr = new CookComputing.MetaWeblog.Post[20];
for (int i = 0; i < 20; i++)
{
infoarr[i].categories = new string[2] { "1", "2" };
infoarr[i].dateCreated = DateTime.Now;
infoarr[i].description = string.Format("说明 {0}", i);
Enclosure el=new Enclosure();
el.length=i;
el.type=i.ToString();
el.url=string.Format("http://{0}.html", i);
infoarr[i].enclosure = el;
infoarr[i].link = string.Format("http://{0}.html", i);
infoarr[i].mt_allow_comments = true;
infoarr[i].mt_allow_pings = true;
infoarr[i].mt_convert_breaks = true;
infoarr[i].mt_excerpt = "mt_excerpt";
infoarr[i].mt_text_more = "more 更多";
infoarr[i].permalink = "";
infoarr[i].postid = i.ToString();
Source su = new Source();
su.name = string.Format("测试 {0}", i);
su.url = string.Format("http://{0}.html", i);
infoarr[i].source = su;
infoarr[i].title = string.Format("标题 {0}", i);
infoarr[i].userid = "1";
}
return infoarr;
}
[XmlRpcMethod("metaWeblog.getPost", Description = "获取日志信息")]
public CookComputing.MetaWeblog.Post getPost(string postid, string username, string password)
{
CookComputing.MetaWeblog.Post p = new CookComputing.MetaWeblog.Post();
p.categories = new string[2] { "1", "2" };
p.dateCreated = DateTime.Now;
p.description = "说明" + postid.ToString();
Enclosure el = new Enclosure();
el.length = 1;
el.type = "2";
el.url = string.Format("http://{0}.html", 3);
p.enclosure = el;
p.link = "link";
p.mt_allow_comments = true;
p.mt_allow_pings = true;
p.mt_convert_breaks = true;
p.mt_excerpt = "mt_excerpt";
p.mt_text_more = "mt_text_more";
p.permalink = "permalink";
p.postid = postid;
Source su = new Source();
su.name = string.Format("测试 {0}", 1);
su.url = string.Format("http://{0}.html", 1);
p.source = su;
p.title = "标题" + postid;
p.userid = "1";
return p;
}
[XmlRpcMethod("metaWeblog.editPost", Description = "修改日志")]
public bool editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
{
return true;
}
}
}