Sharepoint 2010 – BCS ECT ,Windows Azure WCF et Bing Maps Partie 2
Une fois que l’on a déployé notre Service WCF et que celui-ci s’avère fonctionnel nous pouvons maintenant nous attaquer à la configuration de notre BCS puis de la création de notre code Sharepoint avec Bing Maps en Silverlight
BCS Configuration
Rendez-vous dans “Sharepoint Administation Central”> Manage Service Application > Business Data Connectivity Service Proxy
Ajoutons les autorisations en cliquant sur “Set Metadata Store Permission” et ajoutez un utilisateur
Depuis Sharepoint Designer ajoutons un External Content Type
Ajoutez un Nom (Stores) et laissez les options par défaut puis ajouter votre Service WCF en cliquant sur “ Click Here to discover external ….”
Ici voici le résultat de ma configuration
Puis cliquez sur “Add connection” puis le type “WCF” et renseignez les paramètres suivants :
– Service WSDL : http://myservice.cloudapp.net/myservice.svc?wsdl
– Service = http://myservice.cloudapp.net/myservice.svc
– Name (optional) : Stores
Laissez le reste par défaut. Ici voici le résultat de ma connection
Dans l’arborescence sélectionnez la méthode GetStore puis cliquez droit sur New Read Item Operation.
Mettez bien en paramètres sur le “Map to Identifier” le champ StoreID et sur Identifier le champ StoreID
Dans l’arborescence sélectionnez la méthode GetStores puis cliquez droit sur New Read List Operation.
Faites de même qu’avec GetStore.
Ensuite générez les formulaires en cliquant sur “Create & Lists Forms” et donnez le nom de “MyStoreBingLists”
Une fois cela réalisé vous devriez avoir côté BCS la configuration Stores disponible et votre liste visible.
External Content Type information
MyStoreBingLists
Sharepoint Project
Prérequis :
· Visual Studio 2010 SharePoint Power tool –http://visualstudiogallery.msdn.microsoft.com/en-us/8e602a8c-6714-4549-9e95-f3700344b0d9
· Microsoft Silverlight Plug-in for Browsers – http://www.microsoft.com/getsilverlight/
· Bing Maps Silverlight Control SDK – http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=beb29d27-6f0c-494f-b028-1e0e3187e830
· Microsoft Silverlight Developer runtime – http://go.microsoft.com/fwlink/?LinkID=188039
Afin de pouvoir publier notre fichier (XAP) silverlight dans Sharepoint, créez avant tout une Bibliothèques de Documents en la nommant “SLLIB”
Ensuite créez un projet Sharepoint vide et lui ajouté un item Elements.xml avec le code suivant :
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="Silverlight Application Module" Url="SLLIB"> <File Path="Silverlight Application ModuleSharePoint2010HOL.xap" Url="Silverlight Application Module/SharePoint2010HOL.xap" Type="GhostableInLibrary"/> </Module> </Elements>
puis lui ajouté un fichier de type module en le nommant Silverlight Application Module puis clic droit propriétés> Project Output References
Si vous êtes perdu voici un lien d’aide : http://bryantlikes.com/GettingStartedWithSilverlightAndSharePoint2010.aspx
Silverlight Project
Ajouter un nouveau projet de type Silverlight et ajouter les références dans MainPage.xaml.cs:
using Microsoft.Maps.MapControl;
using Microsoft.SharePoint.Client;
Design
Le code XAML est le suivant :
<UserControl x:Class="SharePoint2010HOL.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl" d:DesignHeight="400" d:DesignWidth="750" > <Grid x:Name="LayoutRoot" Background="White" > <m:Map x:Name="MainMap" CredentialsProvider="KEYBINGMAPS" AnimationLevel="Full" Mode="AerialWithLabels" ZoomLevel="5" Center="38.000,-95.000" > <m:Map.Children> <m:MapLayer x:Name="PolygonsLayer" Visibility="Visible"/> <m:MapLayer x:Name="Pushpins" Visibility="Visible"/> <m:MapLayer x:Name="ContentPopupLayer"> <Canvas x:Name="ContentPopup" Visibility="Collapsed" Opacity="0.9"> <Rectangle x:Name="ContentPopupRectangle" Fill="White" Canvas.Left="0" Canvas.Top="0" Height="100" Width="300" RadiusX="10" RadiusY="10"/> <StackPanel Canvas.Left="10" Canvas.Top="10"> <TextBlock x:Name="ContentPopupText" FontSize="12" FontWeight="Bold" ></TextBlock> <TextBlock x:Name="ContentPopupDescription" Width="275" FontSize="12" TextWrapping="Wrap"/> </StackPanel> </Canvas> </m:MapLayer> </m:Map.Children> </m:Map> </Grid> </UserControl>
Code-Behind XAML
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Maps.MapControl; using Microsoft.SharePoint.Client; namespace SharePoint2010HOL { public partial class MainPage : UserControl { ListItemCollection listItems; public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { //ClientContext context = new ClientContext("http://vwk-sp2010/sites/demo/"); ClientContext context = new ClientContext(ApplicationContext.Current.Url); List customersList = context.Web.Lists.GetByTitle("MyStoreBingLists"); CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery(); query.ViewXml = @"<View>" + @"<Query><OrderBy>" + @"<FieldRef Name='StoreName' Ascending='True' />" + @"</OrderBy></Query>" + @"<ViewFields>" + @"<FieldRef Name='StoreID' />" + @"<FieldRef Name='StoreName' />" + @"<FieldRef Name='StoreHours' />" + @"<FieldRef Name='StorePhone' />" + @"<FieldRef Name='StoreLongitude' />" + @"<FieldRef Name='StoreLatitude' />" + // @"<FieldRef Name='StoreTitle' />" + @"<FieldRef Name='StoreAddress' />" + @"</ViewFields>" + @"</View>"; listItems = customersList.GetItems(query); context.Load(listItems, items => items.Include( item => item["StoreID"], item => item["StoreName"], item => item["StoreHours"], item => item["StorePhone"], item => item["StoreLongitude"], item => item["StoreLatitude"], //item => item["StoreTitle"], item => item["StoreAddress"] )); context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), new ClientRequestFailedEventHandler(OnRequestFailed)); } private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args) {this.Dispatcher.BeginInvoke(DisplayCustomerInfo); } private void DisplayCustomerInfo() { foreach (ListItem item in listItems) { Pushpins.Children.Clear(); for (int i = 0; i < listItems.Count; i++) { string description = "Store: " + listItems[i].FieldValues["StoreName"].ToString() + "nAddress: " + listItems[i].FieldValues["StoreAddress"].ToString() + "nPhone: " + listItems[i].FieldValues["StorePhone"].ToString() + "nHours: " + listItems[i].FieldValues["StoreHours"].ToString(); CreatePushpin(new Location(Convert.ToDouble(listItems[i].FieldValues["StoreLatitude"].ToString()), Convert.ToDouble(listItems[i].FieldValues["StoreLongitude"].ToString())), description); }} } private void OnRequestFailed(object sender, ClientRequestFailedEventArgs e) { Dispatcher.BeginInvoke(() => { MessageBox.Show("Error: " + e.Message);}); } private void CreatePushpin(Location location, string description) { Pushpin pushpin = new Pushpin(); pushpin.Width = 7; pushpin.Height = 10; pushpin.Tag = description; pushpin.Location = location; Pushpins.AddChild(pushpin, location, PositionOrigin.Center); pushpin.MouseEnter += new MouseEventHandler(Shape_MouseEnter); pushpin.MouseLeave += new MouseEventHandler(Shape_MouseLeave); } private void Shape_MouseEnter(object sender, MouseEventArgs e) { if (sender.ToString() == "Microsoft.Maps.MapControl.Pushpin") { Pushpin content = sender as Pushpin; Canvas.SetZIndex(content, 500); ContentPopupText.Text = content.Name; ContentPopupDescription.Text = content.Tag.ToString(); } else { MapPolygon content = sender as MapPolygon; Canvas.SetZIndex(content, 500); ContentPopupText.Text = "Polygon ID: " + content.Name; ContentPopupDescription.Text = content.Tag.ToString(); } Point point = e.GetPosition(MainMap); Location location = MainMap.ViewportPointToLocation(point); MapLayer.SetPosition(ContentPopup, location); MapLayer.SetPositionOffset(ContentPopup, new Point(25, -50)); ContentPopup.Visibility = Visibility.Visible; } private void Shape_MouseLeave(object sender, MouseEventArgs e) { UIElement content = sender as UIElement; Canvas.SetZIndex(content, 100); ContentPopup.Visibility = Visibility.Collapsed; } } }
APP.XAML
Modifiez la méthode “Application_Startup” afin qu’elle puisse bénéficier du Context Sharepoint
private void Application_Startup(object sender, StartupEventArgs e) { ApplicationContext.Init(e.InitParams, SynchronizationContext.Current); this.RootVisual = new MainPage(); }
Déploiement XAP
Cliquez droit sur le projet Sharepoint et faire “Deploy”. Vérifiez dans la Bibliothèque “SLLIB” que le fichier XAP s’est bien déployé. Puis ajoutez une Web Part Silverlight à votre page et renseignez lui le chemin absolu de votre fichier .xap.
Cela nous donnera le résultat final suivant :
March 9, 2012 at 8:43 am
Article writing is also a fun, if you be acquainted with after that you can write or else it
is difficult to write.
LikeLike
May 9, 2012 at 6:16 am
my silverlight test app runs fine and shows the calnedar or button.i’m running firefox 3.0.11 with the latest version of IE tab 1.5x, i have also tried it in IE 7.0.5730.13 with the exact same results.I am running visual studio 2008 sp1, IIS 6, Moss 2007 sp1, windows server 2003 sp2.i have installed silverlight 2 sdk, silverlight tools for visual studio 1.2 and the version of system.web.silverlight i am using is 2.0.30825.0.next i was gonna try the silverlight media player example but fear i will end up with the same result.Another difference is that i am targeting the 3.5 framework in the web.config while you were using 4.0.thanks again.
LikeLike
May 9, 2012 at 5:26 pm
I did face all sorts of issues like that. It was a real nimtaghre to get Silverlight running in MOSS for the first time. So you’re page doesn’t show any sign of silverlight; white page I assume. Do you get a javascript error in the bottom right corner of your screen if so what does it say? When you right click on the white screen do you get Silverlight menu item? Does your page.aspx inherit masterpage yet or is it just running without a masterpage? If you’re running with masterpage make sure you have added transitional DTD to the HTML definition of your masterpage.
LikeLike