Page History: MetaService 1.0 : Creating a .NET client
Compare Page Revisions
Page Revision: 2009/05/13 00:26
The .Net platform has excellent support for consuming a web service in all versions of Visual Studio 200x.
In Visual Studio 2008 (.NET framework 3.5) you have the ability to create a Service Reference and in previous versions there is the ability to create a Web Reference.
Creating a Web Reference (Visual Studio 2003/2005 .NET 2.0/3.0)
This is the only option for Visual Studio 2003 and 2005 but also available in 2008. Use this in 2008 if you want create a lightweight client that relies on the much smaller and much more available .net framework 2.0.
Actions:
- Create a new project
- Right click your new project and select 'add a Web Reference'
Visual Studio will now have generated code that makes implementing a client look this:
using System;
using MetaServiceClientNet20.com.companywebcast.services;
namespace MetaServiceClientNet20
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = "testusername";
string password = "testpassword";
MetaService client = new MetaService();
int SearchResult;
bool hasResult;
WebcastSummary[] Summaries;
client.WebcastSearch(username, password, null, null, null, null, null, false, null, false, null, false, 0, true, 100, true, out SearchResult, out hasResult, out Summaries);
int GetResult;
Webcast Webcast;
client.WebcastGet(username, password, Summaries0.Id, Summaries0.Languages0, out GetResult, out hasResult, out Webcast);
}
}
}
The file below is a more elaborate client sample, implemented as a Class.
This Class shows more of the behaviour of the MetaService, as well as retrieving large result sets and having to enter your credentials only once. Best of all, it's really well documented.
You'd use the Class like this:
MetaWrapper metaService = new MetaWrapper("testusername", "testpassword");
// Let's retrieve all Webcasts that are Live right now, or will be soon.
// Because a Webcast automatically gains the PreLive Status 30 minutes before PlannedStart
// we can just search for all Live and PreLive Webcasts.
WebcastStatus status = WebcastStatus.PreLive | WebcastStatus.Live;
// Plot a list of all (almost) live webcasts by their title with the link to open
// the specific webcast.
foreach(WebcastSummary summary in metaService.WebcastSearch(null,null,null,null,null,null,status))
{
Webcast webcast = metaService.WebcastGet(summary.Id, summary.Languages0);
Console.WriteLine("{0} - {1}", webcast.Title, webcast.RegisterUrl);
}
Creating a Service Reference (Visual Studio 2008 .NET 3.5)
This is the preferred method if you have Visual Studio 2008, and it's the only method available when building a Silverlight client.
Actions:
- Create a new project
- Right click your new project and select 'add a Service Reference'.
Visual Studio will now have generated some WCF based code that makes implementing a client look like this:
using System;
using MetaClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = "testusername";
string password = "testpassword";
MetaServiceClient client = new MetaServiceClient();
WebcastSummaries Summaries;
int SearchResult = client.WebcastSearch(out Summaries, username, password, null, null, null, null, null, null, null, 0, 100);
Webcast Webcast;
int GetResult = client.WebcastGet(out Webcast, username, password, Summaries0.Id, Summaries0.Languages0);
}
}