This past week I attended and worked at TechEd 2009 in Los Angeles. You can check out all of the conference details here: http://www.msteched.com/teched/default.aspx.

Overall, there were a lot of great sessions and speakers, and it was great to get to see a lot of the people with whom I talk over email but so rarely get to see in person. There are some great talks on the MS TechEd Online site, which is here: http://www.msteched.com/online/home.aspx. (Martin Harwar and I recorded a short session on Silverlight and SharePoint.)

One of the sessions I did this week was on SharePoint and Web Services, and as promised I’ve posted the deck and the code samples from the session to my Skydrive. (You’ll note that I’ve also got a bunch of collateral and resources posted to my Skydrive from past conferences and lots of resources for SharePoint developers.)

http://cid-40a717fc7fcd7e40.skydrive.live.com/browse.aspx/TechEd%7C_USA%7C_2009

On the above link, you’ll find code samples that illustrate the following:

  • SharePoint object model integration (creates a site in an existing site collection)
  • Consumption of native SharePoint web service (updates a list)
  • App that shows different code syntax across SP OM integration, native web services , WCF service, and ASMX service.
  • Integration between Silverlight and SharePoint (that uses a service to call into SharePoint to update a list).

Most of the above are client apps, and use the following code snippets which you can use to create your services. The service-code requires you create a list called TR8. The service is then deployed to IIS 7.0.

ASMX Web Service Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Microsoft.SharePoint;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class UpdateSharePointList : System.Web.Services.WebService
{
    public UpdateSharePointList () {

    }

    [WebMethod]
    public void useNormalMOSSApi(string SalesSPSite, string productName, string productNumber, string FY08Sales)
    {
        string strDashListRoot = SalesSPSite;

        using (SPSite site = new SPSite(strDashListRoot))
        {
            using (SPWeb web = site.OpenWeb())
            {
                web.AllowUnsafeUpdates = true;

                SPList list = web.Lists["TR8"];
                SPListItem Item = list.Items.Add();
                Item["Title"] = productName;
                Item["ProductNum"] = productNumber;
                Item["Sales"] = FY08Sales;
                Item.Update();
            }
        }

    }
}

WCF Web Service Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.SharePoint;


{
    public void useNormalMOSSApi(string SalesSPSite, string productName, string productNumber, string FY08Sales)
    {
        string strDashListRoot = SalesSPSite;

        using (SPSite site = new SPSite(strDashListRoot))
        {
            using (SPWeb web = site.OpenWeb())
            {
                web.AllowUnsafeUpdates = true;

                SPList list = web.Lists["TR8"];
                SPListItem Item = list.Items.Add();
                Item["Title"] = productName;
                Item["ProductNum"] = productNumber;
                Item["Sales"] = FY08Sales;
                Item.Update();
            }
        }

    }
}