User Group Speech Video: Sharepoint Integration

Using Biztalk 2010, ESB 2.1, WorkFlow, AppFabric or Azure as Middleware for message routing to Sharepoint BCS.

Share on Facebook

Integration Users Group KickOff Speech

Main Overview of speech

Once I have re-edited the BizTalk Exposed endpoints to allow for Create, Update and Delete I will publish the source code.

Share on Facebook

Composite Guidance for Integration (Alpha)

We got our own Prism!

http://compositeservices.codeplex.com/

Share on Facebook

Sharepoint Client Object model access from WCF (SOA) service.

Customers.svc

  <%@ ServiceHost Language=”C#” Debug=”true” Service=”MIA.Speech1.WcfService.Customers” CodeBehind=”Customers.svc.cs” %>

Customers.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using MIA.Speech1.Helpers;

namespace MIA.Speech1.WcfService
{
public class Customers : ICustomers
{

public List GetAllCustomers() {
return ClientObjectModelHelper.GetAllCustomers();

}

public Customer GetCustomerByID(string id) {
return ClientObjectModelHelper.GetCustomerByID(id);
}

public List CreateCustomer(string lastName, string firstName, string email, string address1) {
Customer c = new Customer();
c.Address1 = address1;
c.LastName = lastName;
c.FirstName = firstName;
c.EmailAddress = email;
return ClientObjectModelHelper.CreateCustomer(c);
}

public bool UpdateEmailAddress(string id, string emailAddress)
{
Customer c = new Customer();
c.idBDC = id;
c.EmailAddress = emailAddress;
return ClientObjectModelHelper.UpdateEmailAddress(c);
}

public bool UpdateName(string id, string lastName, string firstName)
{
Customer c = new Customer();
c.idBDC = id;
c.LastName = lastName;
c.FirstName = firstName;
return ClientObjectModelHelper.UpdateEmailAddress(c);
}
}
}

ICustomers.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using MIA.Speech1.Helpers;

namespace MIA.Speech1.WcfService
{

[ServiceContract]
public interface ICustomers
{
[OperationContract]
List GetAllCustomers();

[OperationContract]
Customer GetCustomerByID(string id);

[OperationContract]
List CreateCustomer(string lastName, string firstName, string email, string address1);

[OperationContract]
bool UpdateEmailAddress(string id, string emailAddress);

[OperationContract]
bool UpdateName(string id, string lastName, string firstName);
}

}

Customer.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace MIA.Speech1.Helpers
{
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class Customer
{
[DataMember]
public string idBDC { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public string EmailAddress { get; set; }
[DataMember]
public string Address1 { get; set; }
}
}

ClientObject Helper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;

namespace MIA.Speech1.Helpers
{
public static class ClientObjectModelHelper
{

public static List GetAllCustomers()
{
using (ClientContext spContext = new ClientContext(ConstantsHelper.SPSiteURI))
{
spContext.AuthenticationMode = ClientAuthenticationMode.Default;

// To Show a list of lists
Web web = spContext.Web;
spContext.Load(web);
spContext.Load(web.Lists);
spContext.ExecuteQuery();
ListCollection ls = web.Lists;
StringBuilder sb = new StringBuilder();
foreach(List eachList in web.Lists)
{
sb.Append(String.Format(“[{0}]n”, eachList.Title));
}
string s = sb.ToString();

//Use CamlQuery to get just the item you want.
Microsoft.SharePoint.Client.List list = spContext.Web.Lists.GetByTitle(ConstantsHelper.CustomerListName);
ListItemCollection items = list.GetItems(new CamlQuery());
spContext.Load(items);
spContext.ExecuteQuery();
//A View
//query.ViewXml = String.Format(“{0}”,lastName);

//return (from a in items.AsEnumerable()
// select new Customer()
// {
// id = Int64.Parse(a.FieldValues[“id”].ToString()),
// EmailAddress = a.FieldValues[“EmailAddress”].ToString(),
// LastName = a.FieldValues[“LastName”].ToString(),
// FirstName = a.FieldValues[“FirstName”].ToString(),
// Address1 = a.FieldValues[“Address1”].ToString()
// }).ToList();
List lc = new List();
foreach(ListItem l in items)
{
Customer c = new Customer();
c.Address1 = l.FieldValues[“Address1”].ToString();
c.EmailAddress = l.FieldValues[“EmailAddress”].ToString();
c.FirstName = l.FieldValues[“FirstName”].ToString();
c.idBDC = l.FieldValues[“BdcIdentity”].ToString();
c.LastName = l.FieldValues[“LastName”].ToString();
lc.Add(c);
}
return lc;
}
}

public static Customer GetCustomerByID(string BDCIdentity)
{
using (ClientContext spContext = new ClientContext(ConstantsHelper.SPSiteURI))
{
Web web = spContext.Web;
spContext.Load(web);
spContext.Load(web.Lists);
spContext.ExecuteQuery();
Microsoft.SharePoint.Client.List list = spContext.Web.Lists.GetByTitle(ConstantsHelper.CustomerListName);
ListItemCollection items = list.GetItems(new CamlQuery());
spContext.Load(items);
spContext.ExecuteQuery();
Customer c = new Customer();
//LINQ doesnt seem to work properly.
//ListItem myCustomerItem = items.Where(b => b.FieldValues[“BdcIdentity”].ToString() == BDCIdentity).FirstOrDefault();
foreach (ListItem myCustomerItem in items)
{
if (myCustomerItem.FieldValues[“BdcIdentity”].ToString() == BDCIdentity)
{
c.idBDC = myCustomerItem.FieldValues[“BdcIdentity”].ToString();
c.EmailAddress = myCustomerItem.FieldValues[“EmailAddress”].ToString();
c.LastName = myCustomerItem.FieldValues[“LastName”].ToString();
c.FirstName = myCustomerItem.FieldValues[“FirstName”].ToString();
c.Address1 = myCustomerItem.FieldValues[“Address1”].ToString();
return c;
}
}
return c;
}
}

public static List CreateCustomer(Customer c)
{
using (ClientContext spContext = new ClientContext(ConstantsHelper.SPSiteURI))
{
Microsoft.SharePoint.Client.List list = spContext.Web.Lists.GetByTitle(ConstantsHelper.CustomerListName);
spContext.AuthenticationMode = ClientAuthenticationMode.Default;
spContext.ExecuteQuery();
ListItemCreationInformation newItem = new ListItemCreationInformation();
ListItem newCustomer = list.AddItem(newItem);
newCustomer[“Address1”] = c.Address1;
newCustomer[“EmailAddress”] = c.EmailAddress;
newCustomer[“LastName”] = c.LastName;
newCustomer[“FirstName”] = c.FirstName;
newCustomer.Update();
spContext.ExecuteQuery();
list.GetItems(new CamlQuery());
return GetAllCustomers();
}
}

public static bool UpdateEmailAddress(Customer c)
{
using (ClientContext spContext = new ClientContext(ConstantsHelper.SPSiteURI))
{
List list = spContext.Web.Lists.GetByTitle(ConstantsHelper.CustomerListName);
spContext.AuthenticationMode = ClientAuthenticationMode.Default;
CamlQuery query = CamlQuery.CreateAllItemsQuery(); ;
ListItemCollection listItems = list.GetItems(query);
// Should only take
spContext.Load(listItems, items => items.Where(a => a.FieldValues[“BdcIdentity”].ToString() == c.idBDC));
spContext.ExecuteQuery();
if (listItems.Count > 0)
{
//Should only be one returned.
listItems[0].FieldValues[“EmailAddress”] = c.EmailAddress;
listItems[0].Update();
spContext.ExecuteQuery();
listItems = list.GetItems(query);
spContext.Load(listItems, items => items.Where(a => a.FieldValues[“BdcIdentity”].ToString() == c.idBDC));
spContext.ExecuteQuery();
return listItems[0].FieldValues[“EmailAddress”].ToString() == c.EmailAddress;
}
return false;
}
}

public static bool UpdateName(Customer c)
{
using (ClientContext spContext = new ClientContext(ConstantsHelper.SPSiteURI))
{
List list = spContext.Web.Lists.GetByTitle(ConstantsHelper.CustomerListName);
spContext.AuthenticationMode = ClientAuthenticationMode.Default;
spContext.AuthenticationMode = ClientAuthenticationMode.Default;
CamlQuery query = CamlQuery.CreateAllItemsQuery(); ;
ListItemCollection listItems = list.GetItems(query);
// Should only take
spContext.Load(listItems, items => items.Where(a => a.FieldValues[“BdcIdentity”] == c.idBDC));
spContext.ExecuteQuery();
//Should only be one returned.
if (listItems.Count > 0)
{
listItems[0].FieldValues[“LastName”]= c.LastName;
listItems[0].FieldValues[“FirstName”] = c.FirstName;
listItems[0].Update();
spContext.ExecuteQuery();
listItems = list.GetItems(query);
spContext.Load(listItems, items => items.Where(a => a.FieldValues[“BdcIdentity”].ToString() == c.idBDC));
spContext.ExecuteQuery();
return listItems[0].FieldValues[“FirstName”].ToString() == c.FirstName && listItems[0].FieldValues[“LastName”].ToString() == c.LastName;
}
return false;
}
}
}
}


Share on Facebook

Building up a VM for Integration Development

Scenario:

I have a Dell 6510E with 8 GB of Ram I needed to use as a Work PC , and run VM’s for User Groups and Demo’s on.   I have created this VM 2-3 times now and I think I have the steps down fairly solidly now.   You may have a different take on this, however from my perspective building up the VM this way allows you to spend your time coding and not having to deal with minor errors here and there.  My first run through without a domain created 20 hours of Troubleshooting multiple insignificant errors.

I will suggest if you are using MSDN to load these that you have software that will mount an ISO (Like MagicDisc).

Requirements:

  1. Server 2008 R2
  2. Proper Drivers installed (working NIC and Wireless)
  3. A decent amount of time.
  4. Wireless Lan Service Feature Enabled. (So you can connect to customer or worksite networks).

Steps

  1. Configure Static Address on Wired Port.
    1. In my home we use the standard 192.168.1.xxx/24 Addresses.
    2. Copy your DNS information down from your router.
    3. [Start]->Right Click [Network] -> [Properties]
    4. Then in top left Click [Change Adapter Settings]
    5. Right Click on your Wired Connection-> [Properties]
    6. My Settings:
    7. Go to Hyper-V Manager and click Virtual Network Manager [My Settings]:
  2. Create your Virtual Machine:
    1. Open [Hyper-V Manager] New->Virtual Machine and create your new machine.  The only out of the ordinary step was making sure that the Network adapter was shown :
    2. Once the VM is completely loaded with Server 2008 R2 then follow the same directions as before to set a static IP locally on the VM:                 
  3. In this Order:
    1. Run DC Promo to upgrade to a Domain. (Why you needed a static IP since AD machines need to run DNS and require a Static IP
    2. Install Visual Studio 2010 Custom setup [Uncheck Sql Server Express]
    3. Install SQL 2008 R2
    4. Install SharePoint 2010 (New Farm instance)
    5. Create User Groups for BizTalk:
      1. Open [Active Directory Users and Computers]
      2.  

      3. Right Click on [Users]
      4. New->[Group] settings: (Universal-Security)  for these groups:                                   and                                       
      5.  Add Administrator to All groups.
    6. Install BizTalk changing the Groups from COMPUTER GROUPS to the Domain Groups you just Created.
    7. Install SharePoint 2010 Designer
    8. Install BizTalk ESB
    9. Setup Secure Store Service ID          
    10. Setup ECT (In my case ECT SQL DB)
    11. Test DB to List
    12. Installed Silverlight 4 Tools for Visual Studio 2010
    13. Installed Windows Azure Tools for Microsoft Visual Studio.
Share on Facebook