asp.net C # invoke XML-RPC remote publishing article

Source: Internet
Author: User
Tags datetime

XML-RPC is a distributed computing protocol for Remote Procedure calls (distant program calls) (remote procedure CALL,RPC) that encapsulates functions via XML and uses the HTTP protocol as a transport mechanism
It is the Xmlrpc interface of WordPress, it is the C # version, used two libraries xml-rpc.net and joeblogs.
Xml-rpc.net is the framework for a. NET client server based on an XML-RPC remote procedure call.

The code is as follows Copy Code


[Xmlrpcurl ("http://www.111cn.net/RPC2")]
public interface Istatename:ixmlrpcproxy
{
[Xmlrpcmethod ("Examples.getstatename")]
String getstatename (int statenumber);
}
Istatename proxy = Xmlrpcproxygen.create ();
String statename = Proxy. Getstatename (41);

Look, the framework itself supports BLOGGERAPI, Meerkatapi, Metaweblogapi, Movabletypeapi these out-of-the-box interfaces, WordPress also supports these API functions.
However, the evil copycat drive me to search for better API encapsulation, joeblogs This is a good choice for WordPress's API library.

The code is as follows Copy Code
String Url = "www.youblogs.com";
String User = "MyUser"; Enter your username
String Password = "MyPassword"; Enter your password

var wp = new Wordpresswrapper (URL, User, Password);

A few test functions ...
var userblogs = WP. Getuserblogs ();
var tags = WP. GetTags ();
var categories = WP. GetCategories ();


var authors = WP. GetAuthors ();
But this library also needs a small transformation, itself has a lot of interfaces are not implemented, need to write a part of the code, this needs to pay attention to the ^_^.
The development process found that the use of Joe blogs published blog can not set the classification, compared to the live Writer blog when the HTTP packet found, WordPress set the classification used by the classification name, rather than the category ID;

OK, after you find the reason, modify Joe Blogs Source:

1. class Joeblogs.post amended to

The code is as follows Copy Code

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. Structural JoeBlogs.XmlRpc.XmlRpcPost modified to

The code is as follows Copy Code

Using System;
Using Cookcomputing.xmlrpc;
Namespace Joeblogs.xmlrpc
{
<summary>
This struct represents the information about a post that could is 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. When creating an article, pass the category name to the category of the article

The code is as follows Copy Code
Post post = new post ();
Post. title = title;
Post. BODY = body;
Post. Categories = new string[] {category. Name};

Everything's done!

Sample code:

The code is as follows Copy Code

public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
public string xmlrpcurl = "http://www.111cn.net/xmlrpc.php";
public string Username = "Liuweihug";
public string Password = "65linyi!!";


Joeblogs.iwordpresswrapper _wpwrapper;
Logininfo logininfo = new Logininfo ();
private int postdoc ()
{
var _wpwrapper = new Wordpresswrapper (Xmlrpcurl, Username, Password);

var post = new post ()
{
BODY = This.richTextBox1.Text,
Categories = new string[] {TextBox2.Text},
Tags = new string[] {"Test"},
Title = This.textBox1.Text,

};
Return _wpwrapper.newpost (post, true);

}
private void Button1_Click (object sender, EventArgs e)
{
Postdoc ();
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.