Can I Post from a Windows Service?

Topics: Business Logic Layer
Feb 25, 2013 at 8:19 PM
While I am aware that Metaweblog should provide a way for me to post to my blog from a windows service I am yet to find a working sample anywhere. The service is written in C# - has anyone done it or know of a library that allows you to post to blogengine.NET?

Feb 25, 2013 at 10:57 PM
Hi - you should be able to do an ajax call to SavePost in admin/AjaxHelper.aspx I believe. Was working on a WCF service, but think the methods mentioned should work for saving posts.

Mar 5, 2013 at 12:08 AM
I'm trying to use the BlogImporter.asmx web service to accomplish my goal here. Code as follows:
  BlogImporter.BlogImporterSoapClient client = new BlogImporter.BlogImporterSoapClient();

  BlogImporter.AuthHeader auth = new BlogImporter.AuthHeader();
  auth.Username = "username";
  auth.Password = "password";

  BlogImporter.ImportPost post = new BlogImporter.ImportPost();
  post.Author = "username";
  post.Title = "Test Post";
  post.Content = "This is a link <a href=\"\">Linkie</a>";

  string result = client.AddPost(auth, post, "", true);
The call to AddPost is working and returning a guid but nothing ever appears on the blog. Any insights?
Mar 5, 2013 at 2:57 PM
More information:

I'm finding that this call does in fact work, however... Our installation is running off the file system. Is there some sort of caching that goes on in the blog engine code? The posts don't appear in the admin however if I look at the file system the post is in fact created. It appears it shows up after the app recycles, which is strange. Should I just file this as a bug or am I "doing it wrong"?

Mar 5, 2013 at 3:41 PM
Blog importer used to import posts, you'd need to restart app for BE to find these new posts.

You can try to use AjaxHelper instead, it has SavePost() web method, but not sure if it will work in your case.
Jan 17, 2014 at 4:03 AM
Hi rttur!

You've mentioned AjaxHelper several times now. May I please ask you for code snippet on how to call AjaxHelper from code-behind?

Specifically, I am modifying the Contact,aspx.cs so that when the user clicks on "send' button, in addition to what it does now I want the code behind to also create a new post and e-mail the new post.Id.

I got everything to wrote (w/o AjaxHelper). When the user opens the email and clicks on the hyperlink he is taken to a page I created where he can edit the post.. But when he clicks on 'Save Post', he gets 'Object reference not set to an instance' error. Which means my Post.Save code (inside the Contact,aspx.cs) is not working. To make matters worse, you can't save any edits on the other posts unless you delete the new post.

Jan 17, 2014 at 6:01 AM
Hi All!

I patched my issue by using a BlogEngine.Core.Post.Reload() after saving my post.

It is a patch so if anyone wants to elaborate on the use of AjaxHelper, I think a lot of coders can use it.

Jan 17, 2014 at 3:47 PM
In 2.9 most .asmx services and helpers replaced with standard Web API, so you should probably use them going forward (/app_code/api).