Below, you'll find code examples for the most common operations on the Community Megaphone
web service API:
Assuming a web service proxy name of CMEventManager, here's how you would
instantiate the web service in Visual Basic:
Code:
Dim MyEvtMgr As CMEventManager.EventManager = New CMEventManager.EventManager()
Before calling certain web methods, you must first authenticate. Here's the syntax in VB:
Code:
Dim Auth As CMEventManager.SvcAuth
Auth = New CMEventManager.SvcAuth()
Auth.Username = "[Your Username]"
Auth.Password = "[Your Password]"
You should declare Auth such that it can be assigned to a property of your EventManager
instance before calling AddEvent, UpdateEvent, or DeleteEvent.
Here's the syntax for adding an event in VB. Note that you need to create and populate
an instance of the CMEvent class to pass into the AddEvent web method, as shown:
Code:
Dim NewEvent As New CMEventManager.CMEvent
'Set CMEvent properties
With NewEvent
.StartTime = [DateTime value]
.EndTime = [DateTime value]
.TimeZoneID = [supported TimeZoneID - get from GetTimeZoneIDs]
.Title = [String value - max of 500 chars]
.Description = [String value - max of 2000 chars]
.EventUrl = [String value]
.EventType = [supported EventType - get from GetEventTypes]
.Address = [String value - max of 100 chars]
.City = [String value - max of 100 chars]
.State = [String value - max 2 chars get supported values from GetStates]
.Zip = [String value - either 5 or 9 chars, numeric only]
.Latitude = [Decimal value]
.Longitude = [Decimal value]
.AudienceID = [Integer array - get supported values from GetAudiences]
.NativeID = [String - internal representation of event ID on your system]
.PromoteViaMsdnFlash = [Boolean indicating whether to include in MSDN Flash]
.PromoteViaLocalEvangelistBlog [Boolean indicating whether to blog event]
End With
Dim ExceptionString As String = ""
Dim Success As Boolean = False
Dim Key As String = "[Your API Key]"
MyEvtMgr.SvcAuthValue = Auth
Success = MyEvtMgr.AddEvent(Key, NewEvent, ExceptionString)
If Not Success Then
MessageBox.Show(ExceptionString, "Errors Occurred")
Else
MessageBox.Show("Event Added.", "Success!")
End If
Here's the syntax for adding an event in VB. Note that you need to create and populate
an instance of the CMEvent class to pass into the AddEvent web method (for existing
events you can call GetEventByKeyID to pre-populate with existing data), as shown:
Code:
Dim NewEvent As CMEventManager.CMEvent
Dim ExceptionString As String = ""
NewEvent = _
CMEventManager.GetEventByKeyID("[Your API Key]", _
"[Your Native Event ID]", ExceptionString)
'optionally add code to check for any
'exceptions in retrieving the existing event
'Update Event start and end times
With NewEvent
.StartTime = [DateTime value]
.EndTime = [DateTime value]
End With
Dim Success As Boolean = False
Dim Key As String = "[Your API Key]"
MyEvtMgr.SvcAuthValue = Auth
Success = MyEvtMgr.UpdateEvent(Key, NewEvent, ExceptionString)
If Not Success Then
MessageBox.Show(ExceptionString, "Errors Occurred")
Else
MessageBox.Show("Event Updated.", "Success!")
End If
Here's the syntax for deleting an event in VB:
Code:
Dim Success As Boolean = False
Dim Key As String = "[Your API Key]"
MyEvtMgr.SvcAuthValue = Auth
Success = MyEvtMgr.DeleteEvent(Key, "[Your Native Event ID]", ExceptionString)
If Not Success Then
MessageBox.Show(ExceptionString, "Errors Occurred")
Else
MessageBox.Show("Event Deleted.", "Success!")
End If
Using the lookup methods exposed by the web service API, you can easily bind
a drop-down in your page to the currently valid values for event types, timezones,
and state codes. The markup below shows an example of using an ASP.NET
ObjectDataSource control to databind a DropDownList control to display the supported
timezones:
Code:
<asp:ObjectDataSource ID="TimeZoneDS" runat="server"
SelectMethod="GetTimeZoneIDs" TypeName="CMEventManager.EventManager">
</asp:ObjectDataSource>
<asp:DropDownList ID="TimeZoneDDL" runat="server"
DataSourceID="TimeZoneDS" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
Demo:
Using this technique allows you to ensure the values you provide to Community
Megaphone are valid and include any new event types, timezones, etc. that may
be added in the future.