xml-rpc(1)-first demo

本文涉及的产品
文本翻译,文本翻译 100万字符
图片翻译,图片翻译 100张
日志服务 SLS,月写入数据量 50GB 1个月
简介: 今天简单的研究了一下xml-rpc,做了一个小demo,使得最近开发的一个blog系统可以试用word2007来发表文章,现在还没有具体的实现,只是试Word能识别我写的Api. MetaWeblogService.

今天简单的研究了一下xml-rpc,做了一个小demo,使得最近开发的一个blog系统可以试用word2007来发表文章,现在还没有具体的实现,只是试Word能识别我写的Api.

MetaWeblogService.cs

img_a6339ee3e57d1d52bc7d02b338e15a60.gif using  System;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
using  System.Collections.Generic;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
using  System.Text;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
using  CookComputing.MetaWeblog;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
using  CookComputing.XmlRpc;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
using  CookComputing.Blogger;
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
img_a6339ee3e57d1d52bc7d02b338e15a60.gif
namespace  BusiDao.MetaWeblog
img_405b18b4b6584ae338e0f6ecaf736533.gifimg_1c53668bcee393edac0d7b3b3daff1ae.gif
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif {
img_33d02437d135341f0800e3d415312ae8.gif    
public class MetaWeblogService : XmlRpcService
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif    
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"blogger.getUsersBlogs", Description = "获取博客信息")]
img_33d02437d135341f0800e3d415312ae8.gif        
public BlogInfo[] getUsersBlogs(string appKey, string username, string password)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            BlogInfo[] infoarr 
= new BlogInfo[1];
img_33d02437d135341f0800e3d415312ae8.gif            
for (int i = 0; i < 1; i++)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].url 
= string.Format("http://{0}.html", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].blogName 
= string.Format("测试 {0}", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].blogid 
= i.ToString();
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif            
return infoarr;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"metaWeblog.getCategories", Description = "获取分类列表")]
img_33d02437d135341f0800e3d415312ae8.gif        
public CategoryInfo[] getCategories(string blogid, string username, string password)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            CategoryInfo[] infoarr 
= new CategoryInfo[5];
img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif            
for (int i = 0; i < 5; i++)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].categoryid 
= i.ToString();
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].description 
= i.ToString();
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].htmlUrl 
= string.Format("http://{0}.html", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].rssUrl 
= string.Format("http://{0}.xml", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].title 
= string.Format("测试 {0}", i);
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif            
return infoarr;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"metaWeblog.newPost", Description = "发表日志")]
img_33d02437d135341f0800e3d415312ae8.gif        
public string newPost(string blogid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
return "1";
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"metaWeblog.getRecentPosts", Description = "获取日志列表")]
img_33d02437d135341f0800e3d415312ae8.gif        
public CookComputing.MetaWeblog.Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts) 
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            CookComputing.MetaWeblog.Post[] infoarr 
= new CookComputing.MetaWeblog.Post[20];
img_33d02437d135341f0800e3d415312ae8.gif            
for (int i = 0; i < 20; i++)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif                infoarr[i].categories 
= new string[2img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"1""2" };
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].dateCreated 
= DateTime.Now;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].description 
= string.Format("说明 {0}", i);
img_33d02437d135341f0800e3d415312ae8.gif                Enclosure el
=new Enclosure();
img_33d02437d135341f0800e3d415312ae8.gif                el.length
=i;
img_33d02437d135341f0800e3d415312ae8.gif                el.type
=i.ToString();
img_33d02437d135341f0800e3d415312ae8.gif                el.url
=string.Format("http://{0}.html", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].enclosure 
= el;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].link 
= string.Format("http://{0}.html", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].mt_allow_comments 
= true;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].mt_allow_pings 
= true;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].mt_convert_breaks 
= true;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].mt_excerpt 
= "mt_excerpt";
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].mt_text_more 
= "more 更多";
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].permalink 
= "";
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].postid 
= i.ToString();
img_33d02437d135341f0800e3d415312ae8.gif                Source su 
= new Source();
img_33d02437d135341f0800e3d415312ae8.gif                su.name 
= string.Format("测试 {0}", i);
img_33d02437d135341f0800e3d415312ae8.gif                su.url 
= string.Format("http://{0}.html", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].source 
= su;
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].title 
= string.Format("标题 {0}", i);
img_33d02437d135341f0800e3d415312ae8.gif                infoarr[i].userid 
= "1";
img_105a1e124122b2abcee4ea8e9f5108f3.gif            }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif            
return infoarr;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"metaWeblog.getPost", Description = "获取日志信息")]
img_33d02437d135341f0800e3d415312ae8.gif        
public CookComputing.MetaWeblog.Post getPost(string postid, string username, string password)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            CookComputing.MetaWeblog.Post p 
= new CookComputing.MetaWeblog.Post();
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif            p.categories 
=  new string[2img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif"1""2" };
img_33d02437d135341f0800e3d415312ae8.gif            p.dateCreated 
= DateTime.Now;
img_33d02437d135341f0800e3d415312ae8.gif            p.description 
= "说明" + postid.ToString();
img_33d02437d135341f0800e3d415312ae8.gif            Enclosure el 
= new Enclosure();
img_33d02437d135341f0800e3d415312ae8.gif            el.length 
= 1;
img_33d02437d135341f0800e3d415312ae8.gif            el.type 
= "2";
img_33d02437d135341f0800e3d415312ae8.gif            el.url 
= string.Format("http://{0}.html"3);
img_33d02437d135341f0800e3d415312ae8.gif            p.enclosure 
= el;
img_33d02437d135341f0800e3d415312ae8.gif            p.link 
= "link";
img_33d02437d135341f0800e3d415312ae8.gif            p.mt_allow_comments 
= true;
img_33d02437d135341f0800e3d415312ae8.gif            p.mt_allow_pings 
= true;
img_33d02437d135341f0800e3d415312ae8.gif            p.mt_convert_breaks 
= true;
img_33d02437d135341f0800e3d415312ae8.gif            p.mt_excerpt 
= "mt_excerpt";
img_33d02437d135341f0800e3d415312ae8.gif            p.mt_text_more 
= "mt_text_more";
img_33d02437d135341f0800e3d415312ae8.gif            p.permalink 
= "permalink";
img_33d02437d135341f0800e3d415312ae8.gif            p.postid 
= postid;
img_33d02437d135341f0800e3d415312ae8.gif            Source su 
= new Source();
img_33d02437d135341f0800e3d415312ae8.gif            su.name 
= string.Format("测试 {0}"1);
img_33d02437d135341f0800e3d415312ae8.gif            su.url 
= string.Format("http://{0}.html"1);
img_33d02437d135341f0800e3d415312ae8.gif            p.source 
= su;
img_33d02437d135341f0800e3d415312ae8.gif            p.title 
= "标题" + postid;
img_33d02437d135341f0800e3d415312ae8.gif            p.userid 
= "1";
img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif            
return p;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_33d02437d135341f0800e3d415312ae8.gif
img_33d02437d135341f0800e3d415312ae8.gif        [XmlRpcMethod(
"metaWeblog.editPost", Description = "修改日志")]
img_33d02437d135341f0800e3d415312ae8.gif        
public bool editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
img_2887d91d0594ef8793c1db92b8a1d545.gifimg_7a2b9a960ee9a98bfd25d306d55009f8.gif        
img_a76e9bb6ed00cf1c9c9f4ee2f04b558b.gif{
img_33d02437d135341f0800e3d415312ae8.gif            
return true;
img_105a1e124122b2abcee4ea8e9f5108f3.gif        }

img_105a1e124122b2abcee4ea8e9f5108f3.gif    }

img_05dd8d549cff04457a6366b0a7c9352a.gif}
相关文章
|
XML JSON 前端开发
Android网络请求,获取数据demo,几种网络请求的区别,JSON 与 XML 的区别、优劣势
Android网络请求,获取数据demo,几种网络请求的区别,JSON 与 XML 的区别、优劣势
250 0
xml-rpc(2)-first demo_v2
        [XmlRpcMethod("blogger.getUsersBlogs", Description = "获取博客信息")]        public BlogInfo[] getUsersBlogs(string appKey, string username, string...
662 0
|
7月前
|
负载均衡 Dubbo Java
Dubbo 3.x:探索阿里巴巴的开源RPC框架新技术
随着微服务架构的兴起,远程过程调用(RPC)框架成为了关键组件。Dubbo,作为阿里巴巴的开源RPC框架,已经演进到了3.x版本,带来了许多新特性和技术改进。本文将探讨Dubbo 3.x中的一些最新技术,包括服务注册与发现、负载均衡、服务治理等,并通过代码示例展示其使用方式。
389 9
|
7月前
|
设计模式 负载均衡 网络协议
【分布式技术专题】「分布式技术架构」实践见真知,手把手教你如何实现一个属于自己的RPC框架(架构技术引导篇)
【分布式技术专题】「分布式技术架构」实践见真知,手把手教你如何实现一个属于自己的RPC框架(架构技术引导篇)
289 0
|
1月前
|
自然语言处理 负载均衡 API
gRPC 一种现代、开源、高性能的远程过程调用 (RPC) 可以在任何地方运行的框架
gRPC 是一种现代开源高性能远程过程调用(RPC)框架,支持多种编程语言,可在任何环境中运行。它通过高效的连接方式,支持负载平衡、跟踪、健康检查和身份验证,适用于微服务架构、移动设备和浏览器客户端连接后端服务等场景。gRPC 使用 Protocol Buffers 作为接口定义语言,支持四种服务方法:一元 RPC、服务器流式处理、客户端流式处理和双向流式处理。
|
4月前
|
Dubbo 网络协议 Java
RPC框架:一文带你搞懂RPC
这篇文章全面介绍了RPC(远程过程调用)的概念、原理和应用场景,解释了RPC如何工作以及为什么在分布式系统中广泛使用,并探讨了几种常用的RPC框架如Thrift、gRPC、Dubbo和Spring Cloud,同时详细阐述了RPC调用流程和实现透明化远程服务调用的关键技术,包括动态代理和消息的编码解码过程。
RPC框架:一文带你搞懂RPC
|
3月前
|
XML 负载均衡 监控
分布式-dubbo-简易版的RPC框架
分布式-dubbo-简易版的RPC框架

相关课程

更多