19
Alerts! Creating alerts using the SP 2010 UI Improvements, custom WCF services and jQuery

SharePoint Alerts with WCF and jQuery

Embed Size (px)

DESCRIPTION

Presentation from SharePoint Saturday New Zealand that used an alerting solution to show how to build 1) a custom WCF web service that returns JSON, 2) how the SP.UI JavaScript namespace is used with the status bar, notifications and modal dialogues and 3) how to call web services from jQuery.

Citation preview

Page 1: SharePoint Alerts with WCF and jQuery

Alerts! Creating alerts using the SP 2010 UI Improvements, custom WCF services and jQuery

Page 2: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

Page 3: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

Introduction (Brief) There a couple of things I “prepared earlier” … a brief explanation

WCF Building a custom WCF service for SharePoint 2010 The focus will not be what the service does but how to wire it up

jQuery Instead of using the ASP.NET Ajax / Script Manager lets talk to the WCF service with jQuery

SharePoint 2010 UI Utilities – Status Bar, Modal Dialog and Notifications The UI glue to show the information to users

Session Breakdown

Page 4: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

The Alert architecture A SharePoint List – the alert storage

A custom WCF Service – the basic business objects / logic and communication mechanism

jQuery – asynchronous data retrieval (on the client)

SP.UI.Status – the presentation layer

Introduction

Page 5: SharePoint Alerts with WCF and jQuery

WCF

Page 6: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

Can build SOAP, REST or Data Services

Supports dynamic configuration using factories. SharePoint 2010 provides 3 factories:

WCF

Service Type Service Factory Description

SOAP service MultipleBaseAddressBasicHttpBindingServiceHostFactory

Basic HTTP binding must be used, which creates endpoints for a service based on the basic HTTP binding.

REST Service MultipleBaseAddressWebServiceHostFactory

The service factory creates endpoints with Web bindings.

ADO.NET Data Service MultipleBaseAddressDataServiceHostFactory

A data service host factory can be used.

Page 7: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

Can’t be deployed by a sandbox solution

WCF isn’t 100% supported in SharePoint project templates Create a separate WCF Service Library and copy the files into the SharePoint

project Add references to System.ServiceModel and System.Runtime.Serialization The service declaration (.svc) needs to be added to list of files processed for

replaceable tokens http://msdn.microsoft.com/en-us/library/ee231545.aspx

Create Alert class that represents our alerts for serialization/data

transfer Alert { Title, Description, Link, Colour }

Custom WCF Service in SharePoint 2010

Page 8: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

Make the service ASP.NET compatible using System.ServiceModel.Activation [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Make the service REST capable using System.ServiceModel.Web [WebGet(UriTemplate = "/Alert", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]

Using MultipleBaseAddressWebServiceHostFactory because its a REST service (sort of)

Custom WCF Service in SharePoint 2010

Page 9: SharePoint Alerts with WCF and jQuery

DEMO: Custom WCF Build

Page 10: SharePoint Alerts with WCF and jQuery

jQuery

Page 11: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

We could use ASP.NET AJAX but … we won’t

We will use jQuery to call our WCF web service jQuery has built in support for ajax and JSON

jQuery.ajax() jQuery.getJSON()

jQuery

Page 12: SharePoint Alerts with WCF and jQuery

User Interface Utilities – SP.UI

Page 13: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

SP.UI.Notify addNotification(), Notify(), removeNotification()

SP.UI.Status addStatus(), appendStatus(), removeAllStatus(), removeStatus(),

setStatusPriColor(), Status(), updateStatus()

SP.UI.ModalDialog.showModalDialog(options) options is a JavaScript literal of the properties to pass this method

e.g. var options = { url: “http://sharepoint.com” }

The OOTB UI Improvements in 2010

Page 14: SharePoint Alerts with WCF and jQuery

DEMO: How to use jQuery and SP.UI

Page 15: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

WCF Services in SharePoint Foundation 2010 http://msdn.microsoft.com/en-us/library/ff521586.aspx

Creating a Custom WCF Service in SharePoint Foundation http://msdn.microsoft.com/en-us/library/ff521581.aspx

jQuery ajax and JSON http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.getJSON/

Resources

Page 16: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

SP.UI.Notify http://msdn.microsoft.com/en-us/library/ff408137.aspx

SP.UI.Status http://msdn.microsoft.com/en-us/library/ff412058.aspx

SP.UI.ModalDialog http://msdn.microsoft.com/en-us/library/ff408909.aspx http://msdn.microsoft.com/en-us/library/ff411351.aspx

Enabling Intellisense in Visual Studio http://msdn.microsoft.com/en-us/library/ff798328.aspx

Resources

Page 17: SharePoint Alerts with WCF and jQuery

SharePoint Saturday New Zealand – WCF, jQuery and the SP Status Bar

SharePoint Consultant at Intergen Blog: nickhadlee.wordpress.com Twitter: @nickhadlee

Nick Hadlee

Page 18: SharePoint Alerts with WCF and jQuery

Questions

Page 19: SharePoint Alerts with WCF and jQuery

Thank you to our Sponsors

MS COMMUNITIES