zoukankan      html  css  js  c++  java
  • xmlrpc(1)first demo

    今天简单的研究了一下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;
            }

        }

    }
  • 相关阅读:
    POJ 3114 Tarjan+Dijkstra
    278. First Bad Version
    209. Minimum Size Subarray Sum
    154. Find Minimum in Rotated Sorted Array II
    153. Find Minimum in Rotated Sorted Array
    710. Random Pick with Blacklist
    767. Reorganize String
    524. Longest Word in Dictionary through Deleting
    349. Intersection of Two Arrays
    350. Intersection of Two Arrays II
  • 原文地址:https://www.cnblogs.com/nasa/p/632344.html
Copyright © 2011-2022 走看看