WordPress 2.7 XML-RPC wrapper for .Net

In a previous posting I described a .Net wrapper for WordPress 2.5. In this new incarnation I’ve added access to the new XML-RPC methods of WP 2.7 like:

GetTags
GetComments
GetPages
GetPage

and an easier API by defining the credentials as constants.  All this allows you now to consult and manage your WP blog through calls like:

WP wp=new WP();
Page[] ps [...]

In a previous posting I described a .Net wrapper for WordPress 2.5. In this new incarnation I’ve added access to the new XML-RPC methods of WP 2.7 like:

  • GetTags
  • GetComments
  • GetPages
  • GetPage

and an easier API by defining the credentials as constants.  All this allows you now to consult and manage your WP blog through calls like:

WP wp=new WP();
Page[] ps = wp.GetPages(3);
Page page= wp.GetPage("655");
Post post = wp.GetPost("1068");
UserInfo info= wp.GetUserInfo();
CommentFilter f = new CommentFilter() { number = 12,offset = 0,post_id = 1068,status = "approve"};
Comment[] c = wp.GetComments(f);
Post[] p = wp.GetRecentPosts(3);
Category[] cats= wp.GetCategories();
TagInfo[] t = wp.GetTags();
 
Image im= Bitmap.FromFile(@"C:\temp\thumbup.jpg");
byte[] barray = WP.ConvertImageToByteArray(im, ImageFormat.Jpeg);
MediaObject media = new MediaObject() { name = "wpapi.jpg", type ="jpg", bits = barray};
MediaObjectInfo minfo = wp.NewMediaObject(media);

You can download this Visual Studio project and don’t forget to fetch a copy of the XML-RPC.Net library from Cook computing (there is a version in the VS solution though).

Tagged with:
 

29 Responses to “WordPress 2.7 XML-RPC wrapper for .Net”

  1. Rob Conery says:

    I have a question for you on this – would you mind dropping me a line when you can at robcon at microsoft? Thanks!

  2. Sent you an email Rob, but you haven’t replied yet. Maybe my mail ended up in your spam-box?

  3. Joe says:

    Francois,

    You are my new hero! You just saved me a ton of time!

    Thanks again!

    Joe

  4. Ric Castagna says:

    Francois,

    Well, I’m stumped. I’ve downloaded both your “necessary” code as well as the Cook Computing XML-RPC .NET library, and can’t even get past your first line:

    WP wp = new WP();

    Intellisense doesn’t find the WP reference and when I leave it in there without relying on Intellisense, I get a complilation error:

    The type or namespace name ‘WP’ could not be found.

    What am I missing here? This looks very cool, and I really want to get it working.

    Thanks!
    Ric

  5. Fetch this project and all will be well :)

  6. Johnny Long says:

    Francois, You are the man. I will be petitioning for your own national holiday this year in honor of your Wordpress Wrapper. Not just a silly holiday ethier, a holiday that banks will be closed on.

  7. JRobs says:

    I am having trouble creating a new category, Any chance you can help me out? I am getting the error

    “Method parameters match the signature of more than one method”

    This is the code I am attempting with.

    #region NewCategory
    public string NewCat(string cat)
    {
    return NewCat(“1″, Username, Password, cat);
    }

    [XmlRpcMethod("wp_newCategory")]
    public string NewCat(string blogid, string username, string password, string cat)
    {
    return (string)this.Invoke(“NewCat”, new object[] { int.Parse(blogid), username, password, cat});
    }

    #endregion

  8. I’ve update the VS solution and included the ‘NewCategory’ method. Note that you’ll get an exception in case the category already exists. So, if you repeat the same addition you will get the second time an error which originates in WordPress and not in the WordPress.Net code.

  9. JRobs says:

    Awesome Francois, thank you so much, by any chance would you know how I can pass the blogurl to the wrapper in the constructor?

  10. Can we use this for posting blog in http://www.wordpress.com??

  11. The XML-RPC access to a WordPress is part of the distribution (installation) of WordPress. If you install WP, it’s there and the wrapper doesn’t need anything else for the default interface of WP. However, maybe some hosts decide to block the access through XML-RPC but that’s more a security issue than anything related to WP or this wrapper.
    I don’t own a WordPress.com blog so I never tried it but if I abuse some other people’s blog and try to access their XML-RPC interface I do get a response. Try it out on any blog via a browser and it will tell you ‘XML-RPC server accepts POST requests only.’ This means that the interface is enabled and present, just that you need the proper XML-RPC client to talk to it.
    Conclusion: yes, you can as far as I can see.

  12. Wow..thank you so much for the great response..yeah, XML-RPC in wordpress.com is enabled by default. so, i guess i have to try…Thanks!

  13. how will i change my username and password during the actual run??

  14. can we use xml-rpc.net library in asp.net websites?

  15. Currently the username/password is a constant and passed as constants but the actual method calls to WP contain username/password parameters which can be changed at runtime. The fact that in my wrapper they are defined as constants is just for convenience.
    You should be able to alter all of this, it’s really simple.

  16. You can use in ASP.Net, in F#, in VB.Net, in any CLR language you like. The XML-RPC interface doesn’t know what kind of client is sending requests.

  17. Like for ex., I would like to make an asp.net website that will be able to post to wordpress using xml-rpc.net library..can i do that?

  18. As I said, this should be no problem. Of course, you should experiment a bit since for example the page timeout of an ASPX could be too short if the WP site (i.e. the XML-RPC interface) is answering slow.

  19. Return DirectCast(Me.Invoke(“NewPost”, New Object() {blogid, username, password, content, publish})

    can you please convert that to vb.net??please..

  20. Can you please answer the mail I sent to you first?

    You don’t need to convert the code to VB.Net if you use the compiled assembly as a reference.

  21. Alex Brown says:

    You can specify the endpoints (url, user name, password) using CookComputing XML RPC.net
    see my little post:

    http://www.alexjamesbrown.com/geek/development/dotnet/specify-xml-rpc-endpoints-at-run-time/

    I’ve also created a .net wrapper for Wordpress, and other blogs (implementing the metaWeblog api)

    http://joeblogs.codeplex.com

  22. MInTheGap says:

    I get an exception on Page[] ps = wp.GetPages(3);

    response contains int value where string expected [response : array mapped to type Page[] : element 0 : struct mapped to type Page : member page_id mapped to type String

    I’m running WP 2.8.4.

  23. Francois says:

    Will have a look at it as soon as I can. Currently The Orbifold is overflown with customer projects and customizations of G2…

  24. MInTheGap says:

    Hey, no problem. I was able to work around that dilemma, but do you have a good way to determine the BlogURL at run time instead of design time?

    I have multiple blogs, and I’m looking for a way to parametrize the connection information instead of having it hard coded. I’ll be attempting it myself, but I wondered if you had any ideas.

  25. Francois says:

    Easy to do. Put the urls in the ‘app.config’ (or ‘web.config’ if you’ve got a web application) and access things this way at runtime (see this article for example).
    You could create a combobox in your application as well to select the url, of course.

  26. Frithjof says:

    I had the same error message, using a wordpress 2.8.4. You need the change the page struct definition:
    public int page_id;
    public int wp_page_order;

    Cheers,
    Frithjof

  27. Suresh says:

    GetPost method not returning complete post, if the post have more tag

  28. [...] for writing an awesome tool, XML-RPC.NET. And I’d also like to thank Orbifold for their Wordpress XML-RPC library which helped decipher the RPC [...]

  29. Sean Olson says:

    Francois,

    great work! Thanks for making this available – a real time saver.

    Sean

Leave a Reply