How to access Outlook and post to a blog using C#

Page 3 of 3
  1. Introduction
  2. Posting to your blog
  3. Accessing the web service

Accessing the web service

Once the web service is up and working, you need to create a web reference to the webservice, this is done in Visual Studio by right clicking the references box and choosing add web reference.  Lets say there's one at http://webservices.nullify.net/blog.asmx

When you add a web reference Visual Studio will automatically produce a wrapping class that will allow you to easily instantiate the web service as a local object, without worrying about any of the underlying technology.  (I'll only cover synchronous calls here, otherwise this will turn into a full fledged book...)

To access the above web service, you would simply define it as a new object:

net.nullify.webservices.Blog blog = new net.nullify.webservices.Blog();

And you would define our NewsItem scructure that we defined in the webservice:

net.nullify.webservices.NewsItem article = new net.nullify.webservices.NewsItem();

This will allow you to now call methods of the blog object, which will execute directly on your web server, with all the rights of a normal ASP.NET page - including the ability to insert articles into your database!

Using our imaginary webservice, rather than writing the subject for each MailItem to the console, you can post them to your blog. So, going back to our original loop that went through all the mail items in a particular Outlook folder:

foreach(Outlook.MailItem t in inboxFld.Items)
{
  article.subject = t.Subject;
   article.content = t.Body;
   article.topic = "OutlookPost";
   blog.AddArticle(article);
}

(Note, this is assuming your webservice has no security, or is protected by ASP.NET/IIS' own security!)

I hope this post helps someone!

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra