• 自己开发Blog博客程序:关于MetaWeblogAPI 的实现 无为而为


    前言

    最近想自己做一个Blog程序玩一下,自己做的博客程序,当然要能够和各种博客的客户端要能够连接起来才行。

    想要连接当然就是要按照标准来做,目前流行的API主要有:

    MetablogAPI  (博客园就是了):http://www.xmlrpc.com/metaWeblogApi

    Blogger API

    MovableTypeAPI

    这些API大同小异,主要功能莫非,取得Blog信息,取得Category,取得Post,新增Post,修改Post。

    实现

    关于XML-RPC:http://www.xmlrpc.com/

    实现的工具:XML-RPC.NET(http://www.xml-rpc.net

    方法步骤

    第一步:下载 Version 2.1.0 has been released: xml-rpc.net.2.1.0.zip

    第二步:解压,

    注意interfaces文件夹(里面提供了IMetablogAPI ,IBloggerAPI 等接口)和

    bin文件夹,(里面提供了CookComputing.XmlRpcV2.dll,V2表示.net 2.0)

    第三步:引入CookComputing.XmlRpcV2.dll,实现服务

    3. Servers

    3.1 What are the different ways in which an XML-RPC server can be implemented?

    There are three ways of implementing an XML-RPC server using XML-RPC.NET:

    1. In IIS using a class derived from XmlRpcService.
    2. Using an XML-RPC formatter with .NET Remoting.
    3. In IIS using an XML-RPC formatter with .NET Remoting.
    3.2 How do I implement an XML-RPC server in IIS?

    Class XmlRpcService implements an HTTP Handler which exposes the IHttpHandler and IRequiresSessionState interfaces. When a class derived from XmlRpcService is configured via a web.config file, incoming XML-RPC requests will be directed to the handler by the ASP.NET runtime.

    Implementing the Service

    XmlRpcService is derived from, adding the custom application function of the Service. The derived class contains one or more public methods which represent the required XML-RPC methods. For example, the SumAndDifference example would be implemented like this:

    public class MetablogAPI : XmlRpcService, IMetaWeblog

       {

    #region IMetaWeblog Members
            public object editPost(string postid, string username, string password, CookComputing.MetaWeblog.Post post, bool publish)
            {
              
                    cmsgames3.Blog_Post blog_Post = db.Blog_Posts.Single(p => p.postid == int.Parse(postid));
                    Post2Blog_Post(username, password, ref blog_Post, post, publish);
                    db.SubmitChanges();
                return true;
            }

    } 

    If this code is saved to a file called MetablogAPI.cs the Service can be built using the following command line:

    csc /r:system.web.dll /r:CookComputing.XmlRpcV2.dll /target:library MetablogAPI .cs  

    This will build a dll assembly called cmsgames3.dll.

    Configuring the Service

    The Service has to be placed in a virtual directory, say xmlrpc in this case, which has a sub-directory called bin. A configuraton file called web.config is created in the virtual root directory containing the following information to specify that the Service should be invoked when a HTTP request arrives for this URL:

    <configuration>
      <system.web> 
        <httpHandlers>
          <add verb="*" path="MetablogAPI.aspx" type="cmsgames3.MetablogAPI,cmsgames3"/>    
    </httpHandlers>
      </system.web>
    </configuration>

    The config file specifies that if the final segment of the URL is SumAndDiff.rem the handler in the class SumAndDifference will be invoked. Note that the assembly qualified name of the class is used so that ASP.NET knows which assembly to load the class from.

    The HTTP verb is specified by a wildcard. The implementation in XmlRpcService handles both POST for XML-RPC method calls and GET to return an automatically generated documentation on the Service. XmlRpcService will reject any other requests with the appropriate HTTP response code.

    The extension used for the URL is �.rem�. This is for convenience because ASP.NET is configured by default to handle a number of extensions including .rem, .aspx, and .asmx. Other extensions could be used, for example .xmlrpc would be an obvious choice, but this involves changing the configuration of the virtual directory via the IIS management snap-in.

    Once the service is configured a quick check can be made by pointing your browser at the URL and verifying that the automatically generated help page is displayed.

     

    4.只要实现了所有的接口,大功告成。

    这些方法是必须的:

    MetablogAPI

    The following methods are supported:

  • 相关阅读:
    WikiPedia技术架构学习笔记
    MySQL 架构设计篇 (十二) 可扩展设计的基本原则
    php前端控制器二
    php前端控制器三
    构建可扩展的WEB站点读书笔记
    发布脚本开发框架代码
    改良dbgrideh的文字过滤
    cxgrid在当前View插入记录
    生成不重复单据编号
    cxgrid按条件计算合计值
  • 原文地址:https://www.cnblogs.com/cleo/p/908339.html
Copyright © 2020-2023  润新知