MetaService 1.0 : Creating a .NET client

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.


Edit

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:
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.Code, 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.Code, summary.Languages0);

Console.WriteLine("{0} - {1}", webcast.Title, webcast.RegisterUrl); }




Edit

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:
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.Code, Summaries0.Languages0); } }


Note that if you happen to be implementing a Silverlight client that consumes the MetaService directly, you'd follow the steps above (as you should) only to find out that your freshly generated proxy isn't functional (as of May 13th 2009 anyway, with the Silverlight 2 SDK).
What's happening here is that Visual Studio generates a proxy pretty much as it would for any other type of WCF client implementation, while Silverlight itself has only limited support for WCF. Luckily the only thing that is preventing us from using the generated proxy is the configuration file called ServiceReferences.ClientConfig that Visual Studio dropped in the root of our project when it generated the proxy.

After you added your Service Reference, a file called ServiceReferences.ClientConfig is created in the root of your project. The section in that file that's preventing Silverlight from working with the proxy looks like this:


Replace the entire section with the code below, and the problem is solved:


Important note:
Do not create a browser based clients that contain your Webcast Management System username and password. If you are looking to implement something like this, please request a new account specifically for the MetaService at .