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);
}
I hope this post helps someone!
Comments