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:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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).
I have a question for you on this – would you mind dropping me a line when you can at robcon at microsoft? Thanks!
By Rob Conery January 29, 2009 - 1:26 amSent you an email Rob, but you haven’t replied yet. Maybe my mail ended up in your spam-box?
By Francois Vanderseypen January 30, 2009 - 4:08 pmFrancois,
You are my new hero! You just saved me a ton of time!
Thanks again!
Joe
By Joe April 20, 2009 - 9:20 amFrancois,
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!
By Ric Castagna May 5, 2009 - 6:26 pmRic
Fetch this project and all will be well
By Francois Vanderseypen May 5, 2009 - 7:22 pmFrancois, 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.
By Johnny Long May 11, 2009 - 7:12 amI 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
By JRobs May 11, 2009 - 7:59 amI’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.
By Francois Vanderseypen May 11, 2009 - 8:46 amAwesome Francois, thank you so much, by any chance would you know how I can pass the blogurl to the wrapper in the constructor?
By JRobs May 11, 2009 - 10:32 amCan we use this for posting blog in http://www.wordpress.com??
By Maurelle Mejos May 29, 2009 - 9:21 amThe 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.
By Francois Vanderseypen May 29, 2009 - 10:13 amI 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.
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!
By Maurelle Mejos May 29, 2009 - 4:56 pmhow will i change my username and password during the actual run??
By Maurelle Mejos June 2, 2009 - 5:23 pmCurrently 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.
By Francois Vanderseypen June 2, 2009 - 8:01 pmYou should be able to alter all of this, it’s really simple.
can we use xml-rpc.net library in asp.net websites?
By Maurelle Mejos June 2, 2009 - 6:51 pmYou 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.
By Francois Vanderseypen June 2, 2009 - 8:02 pmLike 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?
By Maurelle Mejos June 2, 2009 - 8:12 pmAs 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.
By Francois Vanderseypen June 2, 2009 - 8:49 pmReturn DirectCast(Me.Invoke(“NewPost”, New Object() {blogid, username, password, content, publish})
can you please convert that to vb.net??please..
By Maurelle Mejos June 3, 2009 - 6:07 pmCan 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.
By Francois Vanderseypen June 3, 2009 - 6:19 pmYou 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
By Alex Brown July 6, 2009 - 4:01 pmI 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.
By MInTheGap August 13, 2009 - 4:57 pmWill have a look at it as soon as I can. Currently The Orbifold is overflown with customer projects and customizations of G2…
By Francois August 14, 2009 - 6:23 amHey, 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.
By MInTheGap August 18, 2009 - 3:51 amEasy 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).
By Francois August 19, 2009 - 6:38 amYou could create a combobox in your application as well to select the url, of course.
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,
By Frithjof September 20, 2009 - 10:01 amFrithjof
GetPost method not returning complete post, if the post have more tag
By Suresh October 28, 2009 - 1:39 pm[...] 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 [...]
By My first cmdlet, Out-Web | Josh Erickson November 12, 2009 - 7:07 amFrancois,
great work! Thanks for making this available – a real time saver.
Sean
By Sean Olson November 19, 2009 - 5:55 amthe download link is broken. where can i download a current version?
By daniel January 10, 2011 - 5:35 pmI’m also getting the response contains int value where string expected.
By Kaos July 7, 2011 - 1:50 pmlink to download the projects gives me a 404. can you pick it up somewhere for me?
By Max Hodges July 13, 2011 - 11:28 amBest,
Max
Has moved.
Please have a look at http://visualizationtools.net/default/cellar/wordpress-xml-rpc-wrapper-for-net/
Also, I haven’t looked/updated things for a while. WordPress is upgrading so fast I cannot follow.
By Francois Vanderseypen July 13, 2011 - 11:48 amTechnically not difficult however to alter or fix things really.