<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Harin Sandhoo&#039;s Blog</title>
	<atom:link href="http://sandhoo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandhoo.wordpress.com</link>
	<description>Just another IT weblog</description>
	<lastBuildDate>Mon, 13 Jun 2011 21:51:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sandhoo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/e4f8e823c98cdcdbfbadcfa397830062?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Harin Sandhoo&#039;s Blog</title>
		<link>http://sandhoo.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sandhoo.wordpress.com/osd.xml" title="Harin Sandhoo&#039;s Blog" />
	<atom:link rel='hub' href='http://sandhoo.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Integrating SharePoint and Mobile devices using Azure AppFabric Service Bus</title>
		<link>http://sandhoo.wordpress.com/2011/06/13/integrating-sharepoint-and-mobile-devices-using-azure-appfabric-service-bus/</link>
		<comments>http://sandhoo.wordpress.com/2011/06/13/integrating-sharepoint-and-mobile-devices-using-azure-appfabric-service-bus/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 15:30:59 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/?p=87</guid>
		<description><![CDATA[Although the WP7 for Azure toolkit has been released, I recently ran into an issue exposing SharePoint data to a WP7 app that I thought was worth sharing.  In this case, we have a SharePoint 2010 farm inside a corporate firewall, needing to expose data from the SharePoint User Profile Service to an application written [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=87&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:small;"><span style="font-family:Calibri;">Although the WP7 for Azure toolkit has been released, I recently ran into an issue exposing SharePoint data to a WP7 app that I thought was worth sharing.  In this case, we have a SharePoint 2010 farm inside a corporate firewall, needing to expose data from the SharePoint User Profile Service to an application written on a WP7 mobile device.  To implement this, we created a Windows Service that hosts a webHttpRelayBinding endpoint so the WP7 application can make simple REST calls to get at the data.  By using a REST based endpoint, that also allowed us to write equivalent client applications for Android and iOS.  Going forward, the windows service can be brought in and managed in SharePoint using the Service Application model, but for a demo, simply installing the windows service on the SharePoint box was sufficient.  </span></span></p>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">High level architecture:</span></span></strong></p>
<p> <a href="http://sandhoo.files.wordpress.com/2011/06/arch.png"><img class="alignnone size-full wp-image-90" title="arch" src="http://sandhoo.files.wordpress.com/2011/06/arch.png" alt="" width="1024" height="499" /></a></p>
<p><span style="font-family:Calibri;font-size:small;"> </span></p>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">WCF Service Contract:</span></span></strong></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;"> For our service we have a service contract defined to as:</span></span></p>
<pre>    [ServiceContract]
    public interface IProfileService
    {
        [OperationContract,
        WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/FarmInfo")
        ]
        FarmInfo GetFarmInfo();

        [OperationContract, 
        WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/Users?q={searchTerms}")
        ]
        UserList GetUsers(string searchTerms);

        [OperationContract, 
        WebGet(
            BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Xml,
            UriTemplate = "/Users/{userId}")
        ]
        Profile GetProfile(string userId);
    }
<span style="font-family:Calibri;font-size:small;"> </span></pre>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">WCF Service Implementation:</span></span></strong></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">I created a class called SPProfileReader which encapsulates the call to the SharePont UserProfileManager.  The service implementation looks something like this:</span></span></p>
<pre>    public class ProfileService : IProfileService
    {
        private static object _synch = new object();
        private static SPProfileReader reader = null;

        private SPProfileReader Instance
        {
            get
            {
                return new SPProfileReader(System.Configuration.ConfigurationManager.AppSettings["SiteUrl"]);
            }
        }

        public FarmInfo GetFarmInfo()
        {
            FarmInfo retVal = null;
            try
            {
                retVal = new FarmInfo()
                {
                    id = "AIS Demos Farm",
                    url = "http://&lt;demo farm url&gt;",
                    centraladminurl = "&lt;central admin url&gt;",
                    description = "This farm is a demo environment meant to showcase Azure and SharePoint integration scenarios."
                };
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
            return retVal;
        }

        public UserList GetUsers(string searchTerms)
        {
            UserList retVal = null;
            try
            {
                using (var rdr = Instance)
                {
                    retVal = rdr.GetUsers(searchTerms);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
            return retVal;
        }

        public Profile GetProfile(string userId)
        {
            Profile retVal = null;
            try
            {
                using (var rdr = Instance)
                {
                    retVal = rdr.GetUserProfile(userId);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
            }
            return retVal;
        }
    }
<span style="font-family:Calibri;font-size:small;"> </span></pre>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">Hosting the WCF Service:</span></span></strong></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">Hosting the WCF Service is pretty straight forward and for completeness looks like this:</span></span></p>
<pre>        public void StartHost()
        {
            try
            {
                //// Build the endpoint URI
                string serviceNamespace = System.Configuration.ConfigurationManager.AppSettings["SBNamespace"];
                string endPoint = System.Configuration.ConfigurationManager.AppSettings["SBEndpoint"];
                Uri address = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespace, endPoint);

                //// Build the service bus credential
                string serviceUser = System.Configuration.ConfigurationManager.AppSettings["SBUser"];
                string serviceKey = System.Configuration.ConfigurationManager.AppSettings["SBKey"];
                TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();
                sharedSecretServiceBusCredential.CredentialType = TransportClientCredentialType.SharedSecret;
                sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName = serviceUser;
                sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret = serviceKey;

                Trace.WriteLine("Opening service bus connection: " + address.ToString());

                //// Create the wcf service host
                host = new WebServiceHost(typeof(ProfileService), address);

                //// Set the binding to WebHttpRelayBinding
                Microsoft.ServiceBus.WebHttpRelayBinding binding = new WebHttpRelayBinding();
                binding.Security.RelayClientAuthenticationType = RelayClientAuthenticationType.None;

                //// Create the endpoint
                ServiceEndpoint se = host.AddServiceEndpoint(typeof(IProfileService), binding, address);
                se.Behaviors.Add(sharedSecretServiceBusCredential);
                ServiceDebugBehavior sdb = host.Description.Behaviors.Find&lt;ServiceDebugBehavior&gt;();
                sdb.HttpHelpPageEnabled = false;

                //// Open host
                host.Open();
                Trace.WriteLine("Host open.");
            }
            catch(Exception e)
            {
                Trace.WriteLine("Exception occured while opening host:");
                Trace.WriteLine(e.ToString());
            }
        }</pre>
<p><span style="font-family:Calibri;font-size:small;"> </span></p>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">Sample WP7 Client Code:</span></span></strong></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">Since the relay service is exposing the endpoint as via REST, integrating with mobile devices becomes trivial.  Note, if this is sensitive / production data, I would recommend utilizing the ACS to secure access to the endpoint (examples of how to do that can be seen in the Azure WP7 SDK).  Here is a bit of code showing how to access some data from the REST endpoint.</span></span></p>
<pre>    public class ServiceProxy
    {
        private const string SBUri = "https://&lt;myaccount&gt;.servicebus.windows.net/SPProfileViewer/";

        public static void GetAllUsers(DownloadStringCompletedEventHandler callback)
        {
            WebClient client = new WebClient();
            string uri = string.Format("{0}Users",SBUri);
            client.DownloadStringCompleted += callback;
            client.DownloadStringAsync(new Uri(uri));
        }

        public static void SearchForUsers(string queryTerm, DownloadStringCompletedEventHandler callback)
        {
            WebClient client = new WebClient();
            string uri = string.Format("{0}Users?q={1}", SBUri, queryTerm);
            client.DownloadStringCompleted += callback;
            client.DownloadStringAsync(new Uri(uri));
        }

        public static void GetUserProfile(string userId, DownloadStringCompletedEventHandler callback)
        {
            WebClient client = new WebClient();
            string uri = string.Format("{0}Users/{1}", SBUri,userId);
            client.DownloadStringCompleted += callback;
            client.DownloadStringAsync(new Uri(uri), userId);
        }

        public static void GetFarmInfo(DownloadStringCompletedEventHandler callback)
        {
            WebClient client = new WebClient();
            string uri = string.Format("{0}FarmInfo", SBUri);
            client.DownloadStringCompleted += callback;
            client.DownloadStringAsync(new Uri(uri));
        }
    }
<span style="font-family:Calibri;font-size:small;"> </span></pre>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">An Important ‘gotcha’ when working with SharePoint and the AppFabric Service Bus:</span></span></strong></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">When hosting our relay service, we noticed that after a while the service host lost the connection to the Service Bus and our service was no longer accessible from the clients.  Working off and on with Microsoft Support for a few weeks, we finally tracked down what the issue was.  When the service creates a connection to the AppFabric Service Bus, it requests a security token.  Every ten minutes or so, the host attempts to renew that token.  The trouble comes in when you try and integrate in with SharePoint.  When you access the SPServiceContext and UserProfileManager and probably a bunch of other SharePoint API calls (as we did in this case), the ServicePointManager.ServerCertificateValidationCallback delegate is changed so that it only trusts the certificates that SharePoint knows about.  Unfortunately, the GTE CyberTrust Root certificate that ultimately signed our Service Bus certificate is not trusted by SharePoint.  If you are experiencing this problem, you may notice errors in your WCF / System.NET trace log such as:</span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">System.Net Error: 0 : [6256] Exception in the HttpWebRequest#3038911:: &#8211; The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.</span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;">System.Net Error: 0 : [6256] Exception in the HttpWebRequest#3038911::EndGetRequestStream &#8211; The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.</span></span></p>
<p><span style="font-family:Calibri;font-size:small;"> </span></p>
<p><strong><span style="font-size:small;"><span style="font-family:Calibri;">The work around is as follows (these are from Mog Liang from Microsoft’s support team):</span></span></strong></p>
<ol>
<li><span style="font-size:small;"><span style="font-family:Calibri;">Download the ACS server certificate’s root CA ‘<em>GTE CyberTrust Global Root</em>’ by accessing ACS service ‘<span style="text-decoration:underline;"><span style="color:#0000ff;">https://&lt;myaccount&gt;.accesscontrol.windows.net/WRAPv0.9/</span></span>’</span></span></li>
<li><span style="font-size:small;"><span style="font-family:Calibri;">Open ‘SharePoint 2010 Central Administration’ tool</span></span></li>
<li><span style="font-size:small;"><span style="font-size:small;"><span style="font-size:small;"><span style="font-family:Calibri;">Open ‘Security -&gt; Manage Trust’ page</span></span></span></span>  <a href="http://sandhoo.files.wordpress.com/2011/06/ca.png"><img class="alignnone size-full wp-image-91" title="ca" src="http://sandhoo.files.wordpress.com/2011/06/ca.png" alt="" width="687" height="370" /></a></li>
<li><span style="font-size:small;"><span style="font-family:Calibri;">Click ‘new’ button, in popup page, input the ‘<em>GTE CyberTrust Global Root’ </em>certificate, give a name, and click OK</span></span></li>
</ol>
<p><span style="font-family:Calibri;font-size:small;"> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=87&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2011/06/13/integrating-sharepoint-and-mobile-devices-using-azure-appfabric-service-bus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>

		<media:content url="http://sandhoo.files.wordpress.com/2011/06/arch.png" medium="image">
			<media:title type="html">arch</media:title>
		</media:content>

		<media:content url="http://sandhoo.files.wordpress.com/2011/06/ca.png" medium="image">
			<media:title type="html">ca</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Azure VM Role to Host SharePoint Functionality</title>
		<link>http://sandhoo.wordpress.com/2011/03/01/using-the-azure-vm-role-to-host-sharepoint-functionality/</link>
		<comments>http://sandhoo.wordpress.com/2011/03/01/using-the-azure-vm-role-to-host-sharepoint-functionality/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 21:27:52 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/2011/03/01/using-the-azure-vm-role-to-host-sharepoint-functionality/</guid>
		<description><![CDATA[I was recently asked by my manager, Vishwas Lele, to look into hosting SharePoint in an Azure VM Role as a part of a demo. Specifically, he wanted to see if it was possible to create a scalable cloud based Excel Services processing engine capability. After a bit of trial and error we found that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=79&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently asked by my manager, <a href="http://vlele.wordpress.com/">Vishwas Lele</a>, to look into hosting SharePoint in an Azure VM Role as a part of a demo. Specifically, he wanted to see if it was possible to create a scalable cloud based Excel Services processing engine capability. After a bit of trial and error we found that it is possible, but you really need to be aware of what you are doing.</p>
<p><strong>[Disclaimer]</strong><br />
I will caveat this by saying licensing considerations aside, doing this is at your own risk as VM Role state is not guaranteed to be maintained. That is, Microsoft could decide to move your image to another physical node and in doing so they will revert to your image baseline. Any customizations / configuration done when the node was brought up in Azure will be lost. As such, all state needs to be stored externally / configured prior to uploading your image / configured using an adapter or startup task. An alternative is to use the Azure Connect components to bring the cloud instances into your domain and host your sql server on premise. The downside though, is that you&#8217;ll be dealing with network latencies and still need to dynamically add / remove nodes from your farm. If you are looking to really host content in the cloud using SharePoint, then you&#8217;d be better off using Office 365 and SharePoint Online.</p>
<p>That being said, the process is pretty straight forward. The high level steps are the similar to what&#8217;s on MSDN. For the demo we:</p>
<ol>
<li>Created the <a href="http://msdn.microsoft.com/en-us/library/gg465391.aspx">base VHD</a>.</li>
<li>Installed the <a href="http://msdn.microsoft.com/en-us/library/gg465409.aspx">Windows Azure Integration Components</a>.</li>
<li>Installed SharePoint bits using SQL Express.</li>
<li>
<div>Created a SharePoint farm using <a href="http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=112">local accounts</a> only (Requires PowerShell).</div>
<ol>
<li>Take note of the port used to host Central Admin as you&#8217;ll need to configure your Azure service definition with this port. (I&#8217;d recommend configuring it to use SSL)</li>
<li>For our demo we configured the following service applications: State Service, Security Token Service Application, Secure Store Service, Application Discovery and Load Balancer Service Application, Excel Services Application, and PerformancePoint Service Application.</li>
</ol>
</li>
<li>Created a web application on port 80 (I&#8217;d recommend configuring it to use SSL on port 443).</li>
<li>
<div>Configured Excel Services.</div>
<ol>
<li>Under Global Settings we configured the File Access method to use &#8216;Process Account&#8217; and allowed enabled &#8216;Allow Cross Domain Access&#8217;.</li>
<li>Under trusted file locations, we added an http location pointing to an unrestricted container in blob storage. This is so we don&#8217;t have to upload the workbook each time a new vm instance is brought online.</li>
</ol>
</li>
<li>
<div>Uploaded the VM to Windows Azure using <a href="http://msdn.microsoft.com/en-us/library/gg465385.aspx">csupload</a>.</div>
<ol>
<li>Note that we did NOT sysprep the image.</li>
</ol>
</li>
<li>
<div>Created the <a href="http://msdn.microsoft.com/en-us/library/gg465379.aspx">service model</a>.</div>
<ol>
<li>The service model should contain the two end points for central admin and the default web application.</li>
<li>Note: It would be a really good idea to configure SharePoint to use SSL and add the certificate here as well, but we didn&#8217;t for this demo.</li>
</ol>
</li>
<li>Deployed the deployment package and brought up a node instance in a hosted service.</li>
<li>Browsed to our central admin and default web application using the local accounts.</li>
</ol>
<p>That&#8217;s it!</p>
<p>One thing we did find, is that the since the Azure load balancer is basically round robin, calls to excel services will fail if you have multiple instances of the VM Role configured in the same hosted service. The reason is that you get load balanced across multiple instances for each request and the Excel Services calls aren&#8217;t atomic. You could write your own service that wraps all the needed Excel Services calls into a since WCF call, or you can simply create multiple hosted services with one VM Instance in each. Then implement your own round robin scheme from the client.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=79&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2011/03/01/using-the-azure-vm-role-to-host-sharepoint-functionality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint 2010 Pluggable Workflow Services with Correlation and External Callbacks</title>
		<link>http://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/</link>
		<comments>http://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/#comments</comments>
		<pubDate>Thu, 27 May 2010 00:35:32 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">https://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/</guid>
		<description><![CDATA[Paul Andrew recently wrote an article on MSDN outlining Pluggable Workflow Services. This blog posting extends that example to explain how to include correlation tokens as well as an external callback mechanism. The point of including correlation tokens is if you want to let multiple events of the same type wait for an external event. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=73&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Paul Andrew recently wrote an article on <a href="http://msdn.microsoft.com/en-us/magazine/ee335710.aspx">MSDN</a> outlining Pluggable Workflow Services. This blog posting extends that example to explain how to include correlation tokens as well as an external callback mechanism. The point of including correlation tokens is if you want to let multiple events of the same type wait for an external event. The point of adding a custom callback mechanism would be if you wanted to have a web part, service application, or custom web service that allows users to progress workflows directly instead of modifying a task list item. For example, if you wanted to provide users with the ability to progress the workflow just by sending an email, you could use this mechanism. Wouter van Vugt has a good Channel 9 <a href="http://channel9.msdn.com/posts/matthijs/Integrating-SharePoint-2010-Workflows-into-Backend-Systems-Using-External-Data-Exchange-Services/">video</a> explaining most of these concepts which I’d recommend watching as well.</p>
<h4>Correlation Tokens</h4>
<p>If you’ve ever created a workflow in SharePoint, then you’ve used correlation tokens with almost every SharePoint related activity, such as CreateTask. So why is correlation needed in your custom local communication service definition? Basically it is a mechanism that allows the workflow runtime to route inbound messages to the correct instance of the persisted activities, if you have more than one activity that is waiting for external communication events. If you are writing a pluggable workflow service and have multiple HandleExternalEvent activities of the same interface type and operation, then you need to provide correlation token capabilities. If you don’t have more than one activity instance in the same workflow persisted and waiting on a particular event, then you don’t have to worry about correlation tokens. Here’s how to add them.</p>
<h5>Add a parameter to the ExternalDataEventArgs</h5>
<p>This parameter is used to pass the correlation token id between the host and the client. <strong> </strong></p>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> [Serializable]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> PrimeCalculatorEventArgs : ExternalDataEventArgs</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span>     <span style="color:#0000ff;">public</span> PrimeCalculatorEventArgs(Guid id, <span style="color:#0000ff;">string</span> tokenId) : <span style="color:#0000ff;">base</span>(id)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span>         <span style="color:#0000ff;">this</span>.TokenID = tokenId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Answer;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> TokenID;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<h5>Modify the ExternalDataExchange interface definition</h5>
<p>There are a number of things you’ll need to do here.</p>
<ol>
<li>Annotate the interface with a CorrelationParameterAttribute. In this you specify the token parameter name as defined in the interface method signature.</li>
<li>Mark each outbound method that is in the CallExternalMethod and HandleExternalEvent pair with a CorrelationInitializerAttribute. The parameters of the outbound methods need to have the token parameter name specified in Step 1.</li>
<li>Once that’s done, you need to mark the inbound method with CorrelationAliasAttribute. The first parameter in the CorrelationAliasAttribute attribute needs to match the token parameter name in Step 1. The second parameter in the CorrelationAliasAttribute needs to match the public property specified in the ExternalDataEventArgs (see above section). Note, with the second parameter the first part (the “e”) doesn’t really matter AFAIK, it’s really the second part of the parameter (the TokenID) that needs to match.</li>
</ol>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> [ExternalDataExchange]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> [CorrelationParameter(<span style="color:#006080;">"tokenId"</span>)]  <span style="color:#008000;">// Step 1</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> IPrimeCalculatorService</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span>     [CorrelationInitializer()]  <span style="color:#008000;">// Step 2</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span>     <span style="color:#0000ff;">void</span> CalculatePrimes(<span style="color:#0000ff;">string</span> tokenId, <span style="color:#0000ff;">int</span> topNumberExclusive);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span>     [CorrelationInitializer()]  <span style="color:#008000;">// Step 2</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span>     <span style="color:#0000ff;">void</span> RequestValidation(<span style="color:#0000ff;">string</span> tokenId);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum12" style="color:#606060;">  12:</span>     [CorrelationAlias(<span style="color:#006080;">"tokenId"</span>,<span style="color:#006080;">"e.TokenID"</span>)]  <span style="color:#008000;">// Step 3</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum13" style="color:#606060;">  13:</span>     <span style="color:#0000ff;">event</span> EventHandler&lt;PrimeCalculatorEventArgs&gt; GetAnswer;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum14" style="color:#606060;">  14:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum15" style="color:#606060;">  15:</span>     [CorrelationAlias(<span style="color:#006080;">"tokenId"</span>, <span style="color:#006080;">"e.TokenID"</span>)]  <span style="color:#008000;">// Step 3</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum16" style="color:#606060;">  16:</span>     <span style="color:#0000ff;">event</span> EventHandler&lt;PrimeCalculatorEventArgs&gt; ValidateAnswer;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum17" style="color:#606060;">  17:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<h5>Implement your SPWorkflowExternalDataExchangeService</h5>
<p>The main differences related to correlation here are that you need to pass along the token id. In CallEventHandler, when you invoke your event handler, the token id is passed along with the ExternalDataEventArgs. This is used internally by the workflow runtime to route the call to the correct activity instance in your workflow.</p>
<p><strong> </strong></p>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> <span style="color:#008000;">/// Implementation of ExternalDataExchangeService / Local Communication Service</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span> <span style="color:#0000ff;">class</span> PrimeCalculatorService: SPWorkflowExternalDataExchangeService, IPrimeCalculatorService</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> SubscriptionsListName = <span style="color:#006080;">"SubscriptionsList"</span>;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span>     <span style="color:#cc6633;">#region</span> IPrimeCalculatorService Members</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> CalculatePrimes(<span style="color:#0000ff;">string</span> tokenId, <span style="color:#0000ff;">int</span> topNumberExclusive)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum12" style="color:#606060;">  12:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum13" style="color:#606060;">  13:</span>         ThreadPool.QueueUserWorkItem(</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum14" style="color:#606060;">  14:</span>             state =&gt;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum15" style="color:#606060;">  15:</span>             {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum16" style="color:#606060;">  16:</span>                 FactoringState factoringState = state <span style="color:#0000ff;">as</span> FactoringState;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum17" style="color:#606060;">  17:</span>                 PrimeCalculatorWS.Calculate ws = <span style="color:#0000ff;">new</span> PrimeCalculatorWS.Calculate();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum18" style="color:#606060;">  18:</span>                 <span style="color:#0000ff;">string</span> answer = ws.CalculatePrimes(factoringState.topNumberExclusive);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum19" style="color:#606060;">  19:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum20" style="color:#606060;">  20:</span>                 SPWorkflowExternalDataExchangeService.RaiseEvent(</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum21" style="color:#606060;">  21:</span>                     factoringState.web,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum22" style="color:#606060;">  22:</span>                     factoringState.instanceId,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum23" style="color:#606060;">  23:</span>                     <span style="color:#0000ff;">typeof</span>(IPrimeCalculatorService),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum24" style="color:#606060;">  24:</span>                     <span style="color:#006080;">"GetAnswer"</span>,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum25" style="color:#606060;">  25:</span>                     <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">object</span>[] { tokenId, answer }  <span style="color:#008000;">// NOTE:  tokenId is passed along as a parameter for the callback.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum26" style="color:#606060;">  26:</span>                 );</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum27" style="color:#606060;">  27:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum28" style="color:#606060;">  28:</span>             },</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum29" style="color:#606060;">  29:</span>             <span style="color:#0000ff;">new</span> FactoringState(WorkflowEnvironment.WorkflowInstanceId, <span style="color:#0000ff;">this</span>.CurrentWorkflow.ParentWeb, topNumberExclusive)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum30" style="color:#606060;">  30:</span>         );</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum31" style="color:#606060;">  31:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum32" style="color:#606060;">  32:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum33" style="color:#606060;">  33:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> RequestValidation(<span style="color:#0000ff;">string</span> tokenId)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum34" style="color:#606060;">  34:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum35" style="color:#606060;">  35:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum36" style="color:#606060;">  36:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum37" style="color:#606060;">  37:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">event</span> EventHandler&lt;PrimeCalculatorEventArgs&gt; GetAnswer;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum38" style="color:#606060;">  38:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">event</span> EventHandler&lt;PrimeCalculatorEventArgs&gt; ValidateAnswer;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum39" style="color:#606060;">  39:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum40" style="color:#606060;">  40:</span>     <span style="color:#cc6633;">#endregion</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum41" style="color:#606060;">  41:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum42" style="color:#606060;">  42:</span>     <span style="color:#cc6633;">#region</span> SPWorkflowExternalDataExchangeService Overrides</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum43" style="color:#606060;">  43:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum44" style="color:#606060;">  44:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> CallEventHandler(Type eventType, <span style="color:#0000ff;">string</span> eventName, <span style="color:#0000ff;">object</span>[] eventData, SPWorkflow workflow, <span style="color:#0000ff;">string</span> identity, IPendingWork workHandler, <span style="color:#0000ff;">object</span> workItem)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum45" style="color:#606060;">  45:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum46" style="color:#606060;">  46:</span>         <span style="color:#0000ff;">string</span> tokenId = (<span style="color:#0000ff;">string</span>)eventData[0];  <span style="color:#008000;">// NOTE:  tokenId is extracted from eventData and passed along with the ExternalDataEventArgs</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum47" style="color:#606060;">  47:</span>         var msg = <span style="color:#0000ff;">new</span> PrimeCalculatorEventArgs(workflow.InstanceId, tokenId);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum48" style="color:#606060;">  48:</span>         msg.Answer = eventData[1].ToString();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum49" style="color:#606060;">  49:</span>         msg.WorkHandler = workHandler;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum50" style="color:#606060;">  50:</span>         msg.WorkItem = workItem;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum51" style="color:#606060;">  51:</span>         msg.Identity = identity;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum52" style="color:#606060;">  52:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum53" style="color:#606060;">  53:</span>         <span style="color:#0000ff;">if</span> (eventName == <span style="color:#006080;">"GetAnswer"</span> &amp;&amp; GetAnswer != <span style="color:#0000ff;">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum54" style="color:#606060;">  54:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum55" style="color:#606060;">  55:</span>             <span style="color:#0000ff;">this</span>.GetAnswer(<span style="color:#0000ff;">null</span>, msg);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum56" style="color:#606060;">  56:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum57" style="color:#606060;">  57:</span>         <span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> (eventName == <span style="color:#006080;">"ValidateAnswer"</span> &amp;&amp; ValidateAnswer != <span style="color:#0000ff;">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum58" style="color:#606060;">  58:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum59" style="color:#606060;">  59:</span>             <span style="color:#0000ff;">this</span>.ValidateAnswer(<span style="color:#0000ff;">null</span>, msg);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum60" style="color:#606060;">  60:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum61" style="color:#606060;">  61:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum62" style="color:#606060;">  62:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum63" style="color:#606060;">  63:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum64" style="color:#606060;">  64:</span>     <span style="color:#cc6633;">#endregion</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum65" style="color:#606060;">  65:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum66" style="color:#606060;">  66:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum67" style="color:#606060;">  67:</span> <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum68" style="color:#606060;">  68:</span> <span style="color:#008000;">/// This is a utility class to store information needed by the queued thread work item.  </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum69" style="color:#606060;">  69:</span> <span style="color:#008000;">/// This isn't relevant to correlation directly, just used by the example and included for completeness.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum70" style="color:#606060;">  70:</span> <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum71" style="color:#606060;">  71:</span> <span style="color:#0000ff;">class</span> FactoringState</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum72" style="color:#606060;">  72:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum73" style="color:#606060;">  73:</span>     <span style="color:#0000ff;">public</span> Guid instanceId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum74" style="color:#606060;">  74:</span>     <span style="color:#0000ff;">public</span> SPWeb web;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum75" style="color:#606060;">  75:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> topNumberExclusive;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum76" style="color:#606060;">  76:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum77" style="color:#606060;">  77:</span>     <span style="color:#0000ff;">public</span> FactoringState(Guid instanceId, SPWeb web, <span style="color:#0000ff;">int</span> topNumberExclusive)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum78" style="color:#606060;">  78:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum79" style="color:#606060;">  79:</span>         <span style="color:#0000ff;">this</span>.instanceId = instanceId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum80" style="color:#606060;">  80:</span>         <span style="color:#0000ff;">this</span>.web = web;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum81" style="color:#606060;">  81:</span>         <span style="color:#0000ff;">this</span>.topNumberExclusive = topNumberExclusive;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum82" style="color:#606060;">  82:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum83" style="color:#606060;">  83:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<h5>Generate strongly typed CallExternalMethod and HandleExternalEvent activities</h5>
<p>This step is optional, but generally a good idea. The tool creates activities for that are strongly typed to your interface definition.</p>
<p>It is located at: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin</p>
<h5>Add your Workflow Service / Local Communication Service to the web.config</h5>
<h5>Create a workflow and start using your correlated activites!</h5>
<h4> </h4>
<h4>External Callback Mechanism</h4>
<p>This section tries to explain how you can create an external callback mechanism that doesn’t live directly within the workflow. Examples would be a web part, custom field type, custom service application, SharePoint hosted WCF service, etc, etc. To accomplish this, you first need to make a few small modifications to your SPWorkflowExternalDataExchange service. The next step is that you need write some code to call your call backs, in this example I’ll use a web part, but it can be anything <em>that is executed within the context of a SharePoint process</em>. The italicized point is key. AFAIK, you can&#8217;t create a standalone application to progress the workflows since the SharePoint workflow runtime isn’t loaded in those processes. Ok, so let’s get started. In the example above there was a RequestValidation and ValidateAnswer event handler I defined in my service contract. This section uses them as defined above.</p>
<h5>SPWorkflowExternalDataExchange modifications</h5>
<p>SPWorkflowExternalDataExchange defines two methods called CreateSubscription and DeleteSubscription. These methods are called by the workflow runtime when you use CallExternalMethod and HandleExternalEvent activities. They allow us to write information about our workflow, the Subscription ID, Workflow ID, and any correlation parameters, to some sort of persistence store so we can access it externally when we want to progress our workflows. Note: the example here was taken from Wouter van Vugt’s Channel 9 video. In this example, I’m just writing the information to a SharePoint list, but you can write it to a database / any other persistance store you like. Just keep in mind that there are fidelity concerns that come in to play here, so a SharePoint list may not be the best place if you need high performance / have lots of workflows.</p>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> <span style="color:#008000;">/// This method's goal is to just persist the subscription.CorrelationProperties to a list.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> <span style="color:#008000;">/// NOTE:  This method uses linq to sharepoint where I to defined my own DataContext using sqlmetal (not shown here).</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span> <span style="color:#008000;">/// This is called automatically by the workflow runtime.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span> <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span> <span style="color:#008000;">/// &lt;param name="subscription"&gt;&lt;/param&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> CreateSubscription(MessageEventSubscription subscription)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span>     EnsureSubscriptionsList(<span style="color:#0000ff;">base</span>.CurrentWorkflow.ParentWeb);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span>     CorrelationProperty correlationProperty = subscription.CorrelationProperties.Where(p =&gt; p.Name != <span style="color:#0000ff;">string</span>.Empty).First();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum12" style="color:#606060;">  12:</span>     <span style="color:#0000ff;">using</span> (DataContext context = <span style="color:#0000ff;">new</span> DataContext(<span style="color:#0000ff;">base</span>.CurrentWorkflow.ParentWeb.Url))</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum13" style="color:#606060;">  13:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum14" style="color:#606060;">  14:</span>         EntityList&lt;SubscriptionsListItem&gt; subscriptions = context.GetList&lt;SubscriptionsListItem&gt;(SubscriptionsListName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum15" style="color:#606060;">  15:</span>         SubscriptionsListItem entity = <span style="color:#0000ff;">new</span> SubscriptionsListItem()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum16" style="color:#606060;">  16:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum17" style="color:#606060;">  17:</span>             SubscriptionId = subscription.SubscriptionId.ToString(),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum18" style="color:#606060;">  18:</span>             WorkflowId = subscription.WorkflowInstanceId.ToString(),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum19" style="color:#606060;">  19:</span>             CustomId = correlationProperty.Value !=<span style="color:#0000ff;">null</span> ? correlationProperty.Value.ToString() : <span style="color:#0000ff;">string</span>.Empty</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum20" style="color:#606060;">  20:</span>         };</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum21" style="color:#606060;">  21:</span>         subscriptions.InsertOnSubmit(entity);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum22" style="color:#606060;">  22:</span>         context.SubmitChanges();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum23" style="color:#606060;">  23:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum24" style="color:#606060;">  24:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum25" style="color:#606060;">  25:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum26" style="color:#606060;">  26:</span> <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum27" style="color:#606060;">  27:</span> <span style="color:#008000;">/// This method's goal is to delete the SharePoint list item when we’re done with it.  </span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum28" style="color:#606060;">  28:</span> <span style="color:#008000;">/// NOTE:  This method uses linq to sharepoint where I to defined my own DataContext using sqlmetal (not shown here).</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum29" style="color:#606060;">  29:</span> <span style="color:#008000;">/// This is called automatically by the workflow runtime.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum30" style="color:#606060;">  30:</span> <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum31" style="color:#606060;">  31:</span> <span style="color:#008000;">/// &lt;param name="subscriptionId"&gt;&lt;/param&gt;</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum32" style="color:#606060;">  32:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> DeleteSubscription(Guid subscriptionId)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum33" style="color:#606060;">  33:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum34" style="color:#606060;">  34:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum35" style="color:#606060;">  35:</span>     <span style="color:#0000ff;">using</span> (DataContext context = <span style="color:#0000ff;">new</span> DataContext(<span style="color:#0000ff;">base</span>.CurrentWorkflow.ParentWeb.Url))</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum36" style="color:#606060;">  36:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum37" style="color:#606060;">  37:</span>         EntityList&lt;SubscriptionsListItem&gt; subscriptions = context.GetList&lt;SubscriptionsListItem&gt;(SubscriptionsListName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum38" style="color:#606060;">  38:</span>         SubscriptionsListItem entity = subscriptions</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum39" style="color:#606060;">  39:</span>             .Where(s =&gt; s.SubscriptionId == subscriptionId.ToString())</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum40" style="color:#606060;">  40:</span>             .FirstOrDefault();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum41" style="color:#606060;">  41:</span>         <span style="color:#0000ff;">if</span> (entity != <span style="color:#0000ff;">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum42" style="color:#606060;">  42:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum43" style="color:#606060;">  43:</span>             subscriptions.DeleteOnSubmit(entity);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum44" style="color:#606060;">  44:</span>             context.SubmitChanges();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum45" style="color:#606060;">  45:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum46" style="color:#606060;">  46:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum47" style="color:#606060;">  47:</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum48" style="color:#606060;">  48:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum49" style="color:#606060;">  49:</span> <span style="color:#008000;">/// Helper method to create the SharePoint list.</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum50" style="color:#606060;">  50:</span> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> EnsureSubscriptionsList(SPWeb web)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum51" style="color:#606060;">  51:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum52" style="color:#606060;">  52:</span>     SPList list = web.Lists.TryGetList(SubscriptionsListName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum53" style="color:#606060;">  53:</span>     <span style="color:#0000ff;">if</span> (list == <span style="color:#0000ff;">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum54" style="color:#606060;">  54:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum55" style="color:#606060;">  55:</span>         Guid listId = web.Lists.Add(SubscriptionsListName, <span style="color:#006080;">""</span>, SPListTemplateType.GenericList);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum56" style="color:#606060;">  56:</span>         list = web.Lists.GetList(listId, <span style="color:#0000ff;">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum57" style="color:#606060;">  57:</span>         <span style="color:#0000ff;">string</span> subscriptionIDFieldName = list.Fields.Add(<span style="color:#006080;">"SubscriptionId"</span>, SPFieldType.Text, <span style="color:#0000ff;">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum58" style="color:#606060;">  58:</span>         <span style="color:#0000ff;">string</span> workflowIDFieldName = list.Fields.Add(<span style="color:#006080;">"WorkflowId"</span>, SPFieldType.Text, <span style="color:#0000ff;">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum59" style="color:#606060;">  59:</span>         <span style="color:#0000ff;">string</span> customIDFieldName = list.Fields.Add(<span style="color:#006080;">"CustomId"</span>, SPFieldType.Text, <span style="color:#0000ff;">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum60" style="color:#606060;">  60:</span>         list.Update();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum61" style="color:#606060;">  61:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum62" style="color:#606060;">  62:</span>         SPView view = list.DefaultView;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum63" style="color:#606060;">  63:</span>         view.ViewFields.Add(subscriptionIDFieldName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum64" style="color:#606060;">  64:</span>         view.ViewFields.Add(workflowIDFieldName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum65" style="color:#606060;">  65:</span>         view.ViewFields.Add(customIDFieldName);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum66" style="color:#606060;">  66:</span>         view.Update();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum67" style="color:#606060;">  67:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum68" style="color:#606060;">  68:</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum69" style="color:#606060;">  69:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<h5>Implement your web part / custom code to progress the workflow</h5>
<p>The key method here is SPWorkflowExternalDataExchangeService.RaiseEvent. This calls in to the workflow as we did above, passing in the workflow instance ID and the correlation token id in the ExternalDataEventArgs if you are using correlation. These parameters can be found wherever we persisted them in the CreateSubscription method defined above. In this example, that information was persisted to a list. A more robust example could look up the correct parameter ids, but this one requires users to enter them manually.</p>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippet" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;">
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum1" style="color:#606060;">   1:</span> [ToolboxItemAttribute(<span style="color:#0000ff;">false</span>)]</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum2" style="color:#606060;">   2:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> WebPart1 : WebPart</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum3" style="color:#606060;">   3:</span> {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum4" style="color:#606060;">   4:</span>     <span style="color:#0000ff;">protected</span> TextBox subId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum5" style="color:#606060;">   5:</span>     <span style="color:#0000ff;">protected</span> TextBox wfInstId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum6" style="color:#606060;">   6:</span>     <span style="color:#0000ff;">protected</span> TextBox corrTokenId;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum7" style="color:#606060;">   7:</span>     <span style="color:#0000ff;">protected</span> Button validate;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum8" style="color:#606060;">   8:</span>     <span style="color:#0000ff;">protected</span> Button invalidate;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum9" style="color:#606060;">   9:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum10" style="color:#606060;">  10:</span>     <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> CreateChildControls()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum11" style="color:#606060;">  11:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum12" style="color:#606060;">  12:</span>         subId = <span style="color:#0000ff;">new</span> TextBox();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum13" style="color:#606060;">  13:</span>         wfInstId = <span style="color:#0000ff;">new</span> TextBox();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum14" style="color:#606060;">  14:</span>         corrTokenId = <span style="color:#0000ff;">new</span> TextBox();</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum15" style="color:#606060;">  15:</span>         validate = <span style="color:#0000ff;">new</span> Button()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum16" style="color:#606060;">  16:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum17" style="color:#606060;">  17:</span>             Text = <span style="color:#006080;">"Valid"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum18" style="color:#606060;">  18:</span>         };</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum19" style="color:#606060;">  19:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum20" style="color:#606060;">  20:</span>         validate.Click += <span style="color:#0000ff;">new</span> EventHandler((s, e) =&gt;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum21" style="color:#606060;">  21:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum22" style="color:#606060;">  22:</span>             SPWorkflowExternalDataExchangeService.RaiseEvent(</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum23" style="color:#606060;">  23:</span>                                    SPContext.Current.Web,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum24" style="color:#606060;">  24:</span>                                    <span style="color:#0000ff;">new</span> Guid(wfInstId.Text),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum25" style="color:#606060;">  25:</span>                                    <span style="color:#0000ff;">typeof</span>(IPrimeCalculatorService),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum26" style="color:#606060;">  26:</span>                                    <span style="color:#006080;">"ValidateAnswer"</span>,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum27" style="color:#606060;">  27:</span>                                    <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">object</span>[] { corrTokenId.Text, <span style="color:#006080;">"Valid answer."</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum28" style="color:#606060;">  28:</span>                            );</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum29" style="color:#606060;">  29:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum30" style="color:#606060;">  30:</span>         });</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum31" style="color:#606060;">  31:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum32" style="color:#606060;">  32:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum33" style="color:#606060;">  33:</span>         invalidate = <span style="color:#0000ff;">new</span> Button()</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum34" style="color:#606060;">  34:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum35" style="color:#606060;">  35:</span>             Text = <span style="color:#006080;">"Invalid"</span></pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum36" style="color:#606060;">  36:</span>         };</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum37" style="color:#606060;">  37:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum38" style="color:#606060;">  38:</span>         invalidate.Click += <span style="color:#0000ff;">new</span> EventHandler((s, e) =&gt;</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum39" style="color:#606060;">  39:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum40" style="color:#606060;">  40:</span>             SPWorkflowExternalDataExchangeService.RaiseEvent(</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum41" style="color:#606060;">  41:</span>                                    SPContext.Current.Web,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum42" style="color:#606060;">  42:</span>                                    <span style="color:#0000ff;">new</span> Guid(wfInstId.Text),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum43" style="color:#606060;">  43:</span>                                    <span style="color:#0000ff;">typeof</span>(IPrimeCalculatorService),</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum44" style="color:#606060;">  44:</span>                                    <span style="color:#006080;">"ValidateAnswer"</span>,</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum45" style="color:#606060;">  45:</span>                                    <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">object</span>[] { corrTokenId.Text, <span style="color:#006080;">"In valid answer."</span> }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum46" style="color:#606060;">  46:</span>                            );</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum47" style="color:#606060;">  47:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum48" style="color:#606060;">  48:</span>         });</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum49" style="color:#606060;">  49:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum50" style="color:#606060;">  50:</span>         Controls.Add(subId);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum51" style="color:#606060;">  51:</span>         Controls.Add(wfInstId);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum52" style="color:#606060;">  52:</span>         Controls.Add(corrTokenId);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum53" style="color:#606060;">  53:</span>         Controls.Add(validate);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum54" style="color:#606060;">  54:</span>         Controls.Add(invalidate);</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum55" style="color:#606060;">  55:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum56" style="color:#606060;">  56:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum57" style="color:#606060;">  57:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:100%;"><span id="lnum58" style="color:#606060;">  58:</span> </pre>
<p><!--CRLF--></p>
<pre style="text-align:left;line-height:12pt;background-color:white;width:100%;"><span id="lnum59" style="color:#606060;">  59:</span> }</pre>
<p><!--CRLF--></p>
</div>
</div>
<h5>Deploy, create your workflow, and use your web part to progress your workflows</h5>
<h5>That’s all there is to it! Hope this helps!</h5>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=73&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Service Management APIs to Automate Azure Deployments</title>
		<link>http://sandhoo.wordpress.com/2009/11/19/using-the-service-management-apis-to-automate-azure-deployments/</link>
		<comments>http://sandhoo.wordpress.com/2009/11/19/using-the-service-management-apis-to-automate-azure-deployments/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 18:27:57 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[Azure]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/?p=52</guid>
		<description><![CDATA[With the latest CTP, Microsoft announced the a ServiceManagement API that can be used to automate builds (at least to your staging environment).  Note:  Screenshots are coming soon. Here’s a simple walkthrough on how to create a certificate for use with the Azure Service Management APIs. Create a self signed certificate Open IIS 7 Features [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=52&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the latest CTP, Microsoft announced the a ServiceManagement API that can be used to automate builds (at least to your staging environment).  Note:  Screenshots are coming soon.</p>
<p>Here’s a simple walkthrough on how to create a certificate for use with the Azure Service Management APIs.</p>
<p><strong>Create a self signed certificate</strong></p>
<ol>
<li>Open IIS 7</li>
<li>Features -&gt; Server Certificates</li>
<li>Create Self-Signed Certificate</li>
<li>Enter a friendly name and click ok.</li>
<li>Export the certificate
<ol>
<li>Start Certificate Manager by clicking on Start -&gt; Run, and entering certmgr.msc</li>
<li>Find your certificate (Mine was located in ‘Trusted Root Certification Authorities’</li>
<li>Export the certificate</li>
</ol>
</li>
</ol>
<p>i.      Right click on -&gt; All Tasks -&gt; Export, click next after the welcome screen.</p>
<p>ii.      Do not export the private key, and click next.</p>
<p>iii.      Select DER encoded binary X.509 (.CER)</p>
<p>iv.      Select a file location</p>
<p>v.      Click on Finish</p>
<p><strong>Associate the certificate with Azure</strong></p>
<ol>
<li>Go to the <a href="https://windows.azure.com/">https://windows.azure.com</a> portal and sign in with your account credentials</li>
<li>Navigate to the Account Tab a nd click on ‘Manage My API Certificates’</li>
<li>Click on Browse, select the certificate that was exported previously, and then click upload.</li>
<li>The certificate should appear in the Installed Certificates list</li>
<li>Start using the Management Service API.
<ol>
<li>Here is sample code from MSDN</li>
</ol>
</li>
</ol>
<p><pre class="brush: csharp;">
HttpWebRequest CreateHttpRequest(Uri uri, string httpMethod, X509Certificate2 accessCertificate, TimeSpan timeout)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Timeout = (int)timeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)timeout.TotalMilliseconds * 100;
request.Method = httpMethod;
request.ClientCertificates.Add(accessCertificate);
request.Headers.Add(Constants.VersionHeader, Constants.VersionTarget);
request.ContentType = Constants.ContentTypeXml;
return request;
}
</pre></p>
<p>Note:  If you are calling this code from a machine where the certificate was not originally generated, then you may need to export the certificate with the private key and install it on that server.  For example, if you are automating builds using TFS, then export the certificate with the private key, and import it on the build server.</p>
<p><strong>To automate deployments with TFS the general steps are:</strong></p>
<ol>
<li>Create and associate a management certificate as outlined above.</li>
<li>Make sure the build server has the certificate installed with the private key.</li>
<li>Create a build for your Azure solution in TFS.</li>
<li>Run cspack.exe to package your deployment package on the build output to package the deployment.</li>
<li>Use the BlobStorage REST APIs / provided StorageClient to upload the package into blob storage.</li>
</ol>
<p><pre class="brush: csharp;">
private static string SendFileToContainer(BlobContainer deploymentContainer, string filePath, string versionName)
{
string retVal = string.Empty;
FileInfo info = new FileInfo(filePath);
string newFileName = DateTime.Now.ToString(&quot;yyyyMMddHHmmss&quot;) + &quot;_&quot; + versionName + &quot;_&quot; + info.Name;
BlobProperties blobProp = new BlobProperties(newFileName);
blobProp.Metadata = new System.Collections.Specialized.NameValueCollection();
blobProp.Metadata.Add(&quot;version&quot;, versionName);
if (deploymentContainer.CreateBlob(blobProp, new BlobContents(File.ReadAllBytes(filePath)), true))
{
retVal = deploymentContainer.ContainerUri.AbsoluteUri + &quot;/&quot; + newFileName;
}
return retVal;
}
</pre></p>
<p><strong>Finally, use the ServiceManagement REST APIs to perform the deployment.  Here’s some more code that may help.</strong></p>
<p><pre class="brush: csharp;">
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
//using AIS.Azure.ServiceManagementWrapper.Constants;
//using AIS.Azure.ServiceManagementWrapper.HelperObjects;
using System.Security.Cryptography.X509Certificates;
namespace AIS.Azure.ServiceManagementWrapper
{
namespace HelperObjects
{
public class HostedService
{
public class HostedServiceProperties
{
public HostedServiceProperties() { }
public string Description { get; set; }
public string AffinityGroup { get; set; }
public string Location { get; set; }
public string Label { get; set; }
}

public class HostedServiceDeploymentRoleInstance
{
public string RoleName { get; set; }
public string InstanceName { get; set; }
public string InstanceStatus { get; set; }
}

public class HostedServiceDeployment
{
public string Name { get; set; }
public string DeploymentSlot { get; set; }
public string PrivateID { get; set; }
public string Status { get; set; }
public string Label { get; set; }
public string Url { get; set; }
public string Configuration { get; set; }
public IEnumerable&lt;HostedServiceDeploymentRoleInstance&gt; RoleInstances { get; set; }
public string UpgradeDomainCount { get; set; }
}
public HostedService() { }

public string Url { get; set; }
public string ServiceName { get; set; }
public HostedServiceProperties Properties { get; set; }
public IEnumerable&lt;HostedServiceDeployment&gt; Deployments { get; set; }

public override string ToString()
{
StringBuilder blder = new StringBuilder();
blder.AppendLine(&quot;ServiceName: &quot; + ServiceName);
blder.AppendLine(&quot;Url: &quot; + Url);
blder.AppendLine(&quot;Description: &quot; + Properties.Description);
blder.AppendLine(&quot;AffinityGroup: &quot; + Properties.AffinityGroup);
blder.AppendLine(&quot;Location: &quot; + Properties.Location);
blder.AppendLine(&quot;Label: &quot; + Properties.Label);
blder.AppendLine(&quot;Deployments:&quot;);
foreach (var deployment in Deployments)
{
blder.AppendLine(&quot;Deployment:&quot;);
blder.AppendLine(&quot;Name:\t\t&quot; + deployment.Name);
blder.AppendLine(&quot;DeploymentSlot:\t&quot; + deployment.DeploymentSlot);
blder.AppendLine(&quot;PrivateID:\t&quot; + deployment.PrivateID);
blder.AppendLine(&quot;Status:\t\t&quot; + deployment.Status);
blder.AppendLine(&quot;Label:\t\t&quot; + deployment.Label);
blder.AppendLine(&quot;\t\tUrl:\t\t&quot; + deployment.Url);
blder.AppendLine(&quot;Configuration:\t&quot; + deployment.Configuration);
blder.AppendLine(&quot;UpgradeDomainCount:\t&quot; + deployment.UpgradeDomainCount);
foreach (var roleinstance in deployment.RoleInstances)
{
blder.AppendLine(&quot;RoleInstance:&quot;);
blder.AppendLine(&quot;RoleName:\t&quot; + roleinstance.RoleName);
blder.AppendLine(&quot;InstanceName:\t&quot; + roleinstance.InstanceName);
blder.AppendLine(&quot;InstanceStatus:\t&quot; + roleinstance.InstanceStatus);
}
}
return blder.ToString();
}

}

namespace Constants
{

class RequestTypes
{
public const string GET = &quot;GET&quot;;
public const string POST = &quot;POST&quot;;
public const string DELETE = &quot;DELETE&quot;;
public const string LIST = &quot;LIST&quot;;
}

class Headers
{
public const string x_ms_version_header = &quot;x-ms-version&quot;;
public const string x_ms_version_value = &quot;2009-10-01&quot;;
public const string x_ms_request_id_header = &quot;x-ms-request-id&quot;;
}

class ContentTypes
{
public const string XML = &quot;xml&quot;;
}

class HostedServices
{
public const string Namespace = &quot;http://schemas.microsoft.com/windowsazure&quot;;
public const string ListHostedServices = &quot;https://management.core.windows.net/{0}/services/hostedservices&quot;;
public const string GetHostedServiceProperties = &quot;https://management.core.windows.net/{0}/services/hostedservices/{1}?embed-detail={2}&quot;;
public const string UpgradeDeploymentByDeploymentSlot = &quot;https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}/?comp=upgrade&quot;;
public const string UpgradeDeploymentByDeploymentName = &quot;https://management.core.windows.net/{0}/services/hostedservices/{1}/deployments/{2}/?comp=upgrade&quot;;
}
}

class ServiceManager
{
public enum DeploymentSlots { Staging, Production};
public enum Mode {Auto, Manual};
private static XNamespace ns = &quot;http://schemas.microsoft.com/windowsazure&quot;;

private ServiceManager()
{
}

private static HttpWebRequest CreateHttpRequest(string requestUri, string httpMethod, X509Certificate accessCertificate, TimeSpan timeout)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.Timeout = (int)timeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)timeout.TotalMilliseconds * 100;
request.Method = httpMethod;
request.ClientCertificates.Add(accessCertificate);
request.Headers.Add(Constants.Headers.x_ms_version_header,
Constants.Headers.x_ms_version_value);
request.ContentType = Constants.ContentTypes.XML;
return request;
}

private static string ValueOrEmpty(XElement element)
{
return (element != null) ? element.Value : string.Empty;
}

private static XElement ProcessResponse(HttpWebRequest request)
{
XElement retVal = null;
using (WebResponse resp = request.GetResponse())
{
using (StreamReader respStream = new StreamReader(resp.GetResponseStream()))
{
string responseText = respStream.ReadToEnd();
retVal = XDocument.Parse(responseText).Root;
}
}
return retVal;
}

/// &lt;summary&gt;
///
/// &lt;/summary&gt;
/// &lt;param name=&quot;subscriptionId&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;certificatePath&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;msTimeout&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static IEnumerable&lt;HostedService&gt; ListHostedServices(string subscriptionId, string certificatePath, double msTimeout)
{
string strUrl = string.Format(Constants.HostedServices.ListHostedServices, subscriptionId);

X509Certificate2 cert = new X509Certificate2(certificatePath);

HttpWebRequest req = CreateHttpRequest(strUrl, RequestTypes.GET, cert, TimeSpan.FromMilliseconds(msTimeout));

var response = ProcessResponse(req);

var serviceList = from svc in response.Descendants(ns + &quot;HostedService&quot;)
select new { Url = svc.Element(ns + &quot;Url&quot;).Value, ServiceName = svc.Element(ns + &quot;ServiceName&quot;).Value };

IEnumerable&lt;HostedService&gt; retVal = new List&lt;HostedService&gt;();
// Populate the service by just getting the values
foreach (var service in serviceList)
{
retVal = retVal.Concat&lt;HostedService&gt;(GetHostedServiceProperties(subscriptionId, service.ServiceName, true, certificatePath, msTimeout));
}
return retVal;
}
/// &lt;summary&gt;
///
/// &lt;/summary&gt;
/// &lt;param name=&quot;subscriptionId&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;serviceName&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;embedDetail&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;certificatePath&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;msTimeout&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static IEnumerable&lt;HostedService&gt; GetHostedServiceProperties(string subscriptionId, string serviceName, bool embedDetail, string certificatePath, double msTimeout)
{
string strUrl = string.Format(Constants.HostedServices.GetHostedServiceProperties, subscriptionId, serviceName, embedDetail.ToString().ToLower());

X509Certificate2 cert = new X509Certificate2(certificatePath);

HttpWebRequest req = CreateHttpRequest(strUrl, RequestTypes.GET, cert, TimeSpan.FromMilliseconds(msTimeout));

XElement response = ProcessResponse(req);

var serviceList = from svc in response.DescendantsAndSelf(ns + &quot;HostedService&quot;)
select new HostedService()
{
Url = svc.Element(ns + &quot;Url&quot;).Value,
ServiceName = svc.Element(ns + &quot;ServiceName&quot;).Value,
Properties = new HostedService.HostedServiceProperties()
{
Description = ValueOrEmpty(svc.Element(ns + &quot;HostedServiceProperties&quot;).Element(ns + &quot;Description&quot;)),
AffinityGroup = ValueOrEmpty(svc.Element(ns + &quot;HostedServiceProperties&quot;).Element(ns + &quot;AffinityGroup&quot;)),
Location = ValueOrEmpty(svc.Element(ns + &quot;HostedServiceProperties&quot;).Element(ns + &quot;Location&quot;)),
Label = ValueOrEmpty(svc.Element(ns + &quot;HostedServiceProperties&quot;).Element(ns + &quot;Label&quot;))
},
Deployments = from deployment in svc.Element(ns + &quot;Deployments&quot;).Elements(ns + &quot;Deployment&quot;)
select new HelperObjects.HostedService.HostedServiceDeployment()
{
Name = ValueOrEmpty(deployment.Element(ns + &quot;Name&quot;)),
DeploymentSlot = ValueOrEmpty(deployment.Element(ns + &quot;DeploymentSlot&quot;)),
PrivateID = ValueOrEmpty(deployment.Element(ns + &quot;PrivateID&quot;)),
Status = ValueOrEmpty(deployment.Element(ns + &quot;Status&quot;)),
Label = ValueOrEmpty(deployment.Element(ns + &quot;Label&quot;)),
Url = ValueOrEmpty(deployment.Element(ns + &quot;Url&quot;)),
Configuration = ValueOrEmpty(deployment.Element(ns + &quot;Configuration&quot;)),
RoleInstances = from roleinstance in deployment.Element(ns + &quot;RoleInstanceList&quot;).Elements(ns + &quot;RoleInstance&quot;)
select new HelperObjects.HostedService.HostedServiceDeploymentRoleInstance()
{
RoleName = ValueOrEmpty(roleinstance.Element(ns + &quot;RoleName&quot;)),
InstanceName = ValueOrEmpty(roleinstance.Element(ns + &quot;InstanceName&quot;)),
InstanceStatus = ValueOrEmpty(roleinstance.Element(ns + &quot;InstanceStatus&quot;))
},
UpgradeDomainCount = ValueOrEmpty(deployment.Element(ns + &quot;UpgradeDomainCount&quot;))
}
};
return serviceList;
}
/// &lt;summary&gt;
///
/// &lt;/summary&gt;
/// &lt;param name=&quot;subscriptionId&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;serviceName&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;deploymentSlot&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;mode&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;packageUrl&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;configuration&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;label&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;roleNameToUpgrade&quot;&gt;Optional.  Pass null or String.Empty if none.&lt;/param&gt;
/// &lt;param name=&quot;certificatePath&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;msTimeout&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static string UpgradeDeploymentByDeploymentSlot(string subscriptionId,
string serviceName,
DeploymentSlots deploymentSlot,
Mode mode,
string packageUrl,
string configuration,
string label,
string roleNameToUpgrade,
string certificatePath,
double msTimeout)
{

string strUrl = string.Format(Constants.HostedServices.UpgradeDeploymentByDeploymentSlot, subscriptionId, serviceName, Enum.GetName(typeof(DeploymentSlots),deploymentSlot).ToLower());

X509Certificate2 cert = new X509Certificate2(certificatePath);

HttpWebRequest req = CreateHttpRequest(strUrl, RequestTypes.POST, cert, TimeSpan.FromMilliseconds(msTimeout));
using (XmlTextWriter requestBodyStream = new XmlTextWriter(req.GetRequestStream(), Encoding.UTF8))
{
//requestBodyStream.Write();
XNamespace azureNS = (string)Constants.HostedServices.Namespace.Clone();
XDocument doc = new XDocument(
new XDeclaration(&quot;1.0&quot;,&quot;utf-8&quot;, &quot;yes&quot;),
new XElement( azureNS + &quot;UpgradeDeployment&quot;,
new XElement(azureNS + &quot;Mode&quot;, Enum.GetName(typeof(Mode), mode).ToLower()),
new XElement(azureNS + &quot;PackageUrl&quot;, packageUrl),
new XElement(azureNS + &quot;Configuration&quot;, configuration),
new XElement(azureNS + &quot;Label&quot;, Convert.ToBase64String( Encoding.UTF8.GetBytes(label)))
));

if (!string.IsNullOrEmpty(roleNameToUpgrade))
{
doc.Root.Element(azureNS + &quot;Label&quot;).AddAfterSelf(new XElement(azureNS + &quot;RoleToUpgrade&quot;, roleNameToUpgrade));
}

doc.Save(requestBodyStream);
}
req.ContentType = &quot;application/xml&quot;;

string retVal = string.Empty;
using (WebResponse response = req.GetResponse())
{
try
{
retVal = response.Headers[Constants.Headers.x_ms_request_id_header];
}
catch(NullReferenceException ex)
{
// The request header was not found
retVal = string.Empty;
}
}

return retVal;
}

}
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=52&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2009/11/19/using-the-service-management-apis-to-automate-azure-deployments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
		<item>
		<title>Limited Azure BlobStorage Javascript client</title>
		<link>http://sandhoo.wordpress.com/2009/08/25/limited-azure-blobstorage-javascript-client/</link>
		<comments>http://sandhoo.wordpress.com/2009/08/25/limited-azure-blobstorage-javascript-client/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 21:25:55 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/?p=36</guid>
		<description><![CDATA[I&#8217;ve been spending a bit of time playing with Azure and wanted to learn a bit more about JQuery and the Rest APIs, so I thought I&#8217;d try and implement some of the Azure BlobStorage Rest Services API using a javascript client.  It&#8217;s not done, but I thought I&#8217;d share what I&#8217;ve got so far. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=36&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a bit of time playing with Azure and wanted to learn a bit more about JQuery and the Rest APIs, so I thought I&#8217;d try and implement some of the Azure BlobStorage Rest Services API using a javascript client.  It&#8217;s not done, but I thought I&#8217;d share what I&#8217;ve got so far.</p>
<p>Link to Files:<br />
<a href="http://azureblobstoragejs.codeplex.com/">http://azureblobstoragejs.codeplex.com/</a></p>
<p>Notes: </p>
<ul>
<li>I&#8217;ve not yet implemented the more useful operations:   putBlob,  putBlock, putBlockList, copyBlob operations (that&#8217;s why it&#8217;s a limited), but the others are there.</li>
<li>I have not yet implemented the conditional headers.</li>
<li>I didn&#8217;t add the timeout parameter to the query string, still on my todo list.</li>
<li>A lot of this code was copied from other parts of the web and I tried to at least leave a link to the original code reference, but sorry if I used code you wrote and didn&#8217;t reference you. </li>
<li>This makes use of the jquery library.</li>
<li>Need to add quite a few comments / document how to use it still.</li>
<li>Need to test against non-local storage.</li>
<li>I wanted to provide a single file implementation so that&#8217;s why everything is just dumped into one big blobstorage.js file.</li>
<li>My javascript isn&#8217;t that great and I know there are a lot of things I can do better here so don&#8217;t be too critical, it&#8217;s just a proof of concept after all.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=36&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2009/08/25/limited-azure-blobstorage-javascript-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
		<item>
		<title>Is SharePoint an OLTP or DSS?</title>
		<link>http://sandhoo.wordpress.com/2009/07/24/is-sharepoint-an-oltp-or-dss/</link>
		<comments>http://sandhoo.wordpress.com/2009/07/24/is-sharepoint-an-oltp-or-dss/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 15:42:35 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[MOSS]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/?p=27</guid>
		<description><![CDATA[A recent deadlocking problem has me thinking about whether SharePoint is an OLTP or DSS?  I suppose the answer is both or it depends on what your using it for as it has quite a bit of overlap, but I&#8217;m curious to hear what other people think or if there is any official guidance from Microsoft on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=27&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://sandhoo.wordpress.com/2009/07/19/sharepoint-workflow-deadlocks/">deadlocking problem</a> has me thinking about whether SharePoint is an OLTP or DSS?  I suppose the answer is both or it depends on what your using it for as it has quite a bit of overlap, but I&#8217;m curious to hear what other people think or if there is any official guidance from Microsoft on this?</p>
<p>There are definite implications as to how to best tune your SQL box depending on how it is being used as seen <a href="http://arshadali.blogspot.com/2008/12/sql-server-max-degree-of-parallelism.html">here</a> [1].  SharePoint implementations that are heavier in user interaction or workflow seem to be more OLTP where tuning sql for parallel execution is not recommended.  &#8220;Parallelism sacrifices CPU resources for speed of execution. Given the high volumes of OLTP, parallel queries usually reduce OLTP throughput and should be avoided.&#8221; [2]  However, in systems that have large complex long running queries (which some of the SharePoint internal queries are), the parallel query execution would seem to help.</p>
<p>Ultimately, the answer is going to be that you should be actively monitoring your system and tune it appropriately, but just wanted to solicit some thoughts on the topic as I&#8217;m not a DB expert.</p>
<p>[1] <a href="http://arshadali.blogspot.com/2008/12/sql-server-max-degree-of-parallelism.html">http://arshadali.blogspot.com/2008/12/sql-server-max-degree-of-parallelism.html</a></p>
<p>[2] <a href="http://technet.microsoft.com/en-us/library/cc966401.aspx">http://technet.microsoft.com/en-us/library/cc966401.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=27&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2009/07/24/is-sharepoint-an-oltp-or-dss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint Workflow Deadlocks</title>
		<link>http://sandhoo.wordpress.com/2009/07/19/sharepoint-workflow-deadlocks/</link>
		<comments>http://sandhoo.wordpress.com/2009/07/19/sharepoint-workflow-deadlocks/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 06:51:30 +0000</pubDate>
		<dc:creator>Harin</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://sandhoo.wordpress.com/?p=6</guid>
		<description><![CDATA[I&#8217;ve been working on an application built on MOSS that is extremely workflow intensive.  The application has a series of infopath forms that progress through a custom approval process workflow we developed using Visual Studio 2005.  After a couple weeks, when we were getting about 1000 forms going through this workflow a day, we noticed that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=6&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on an application built on MOSS that is extremely workflow intensive.  The application has a series of infopath forms that progress through a custom approval process workflow we developed using Visual Studio 2005.  After a couple weeks, when we were getting about 1000 forms going through this workflow a day, we noticed that we were getting about 10 or so that would just fail inexplicably.  When we terminated and restarted the workflows, they went through the approval process with no issues.</p>
<p>We then started to really dig into our diagnostics.  We checked our custom logging, the SharePoint logs, Event Logs, the workflow trace logs, SQL Server logs, and all the performance counters we could think of.  We noticed that under load we were seeing a number of lock escalations and periodic deadlock errors on our SQL profiler trace and sure enough, if the WF runtime process hosted inside MOSS was the one terminated by SQL we would see a corresponding entry in our workflow runtime trace file. [<a href="#bm1">1</a>] </p>
<p style="text-align:left;">We also saw quite a few different processes involved in our deadlock graphs, but they all could be traced back to the proc_UpdateListItemWorkflowInstanceData stored procedure in the content db, which is called when the workflows start and at each persist point.</p>
<p>So, we did the next logical thing and tried to reproduce the error in our testing environment so we could troubleshoot and deploy a fix.  The only thing was, we couldn&#8217;t reproduce it.  It turns out, because we were performing functional testing on a virtualized environment there was never enough load put on the SQL box to see the problem.  We had to pave a machine and install a native 64 bit SQL Server 2005 Enterprise Edition to see it.  Our infrastructure was set up in a large farm topology with 2 WFEs, 1 Index, 1 Search, and a 2 Node active-passive clustered SQL Server 2005 instance.  All the MOSS boxes in production were 32 bit and the SQL nodes were 64 bit, and our testing environment was virtualized so all 32 bit.</p>
<p>I&#8217;ll spare you the details of the trial and error process we went through to track these down, but to get rid of most of our deadlocks we ultimately had to:</p>
<p>1. Ensure our lists do not contain a large number of items.<br />
2. Set the maximum degree of parallelism on our SQL box to 1 (MAXDOP=1)<br />
3. Periodically run DBCC FREEPROCCACHE, especially after the weekly SharePoint update statistics timer job is run.</p>
<p><a name="bm1">[1] Error in the WF Trace File:</a><br />
<span style="color:#ff0000;">System.Workflow.Runtime.Hosting Error: 0 : DefaultWorkflowCommitWorkBatchService caught exception from commitWorkBatchCallback: System.Data.SqlClient.SqlException: </span><span style="color:#0000ff;"><span style="color:#ff0000;">Transaction (Process ID 152) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</span><br />
</span>   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)<br />
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)<br />
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)<br />
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)<br />
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)<br />
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)<br />
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)<br />
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)<br />
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()<br />
   at Microsoft.SharePoint.Utilities.SqlSession.ExecuteNonQuery(SqlCommand command)<br />
   at <span style="color:#ff0000;">Microsoft.SharePoint.Workflow.SPWorkflowManager.SaveInstanceData</span>(Guid trackingId, Stream instanceStream, DateTime wakeupTime, Boolean workflowCompleted, Boolean workflowSuspended, Boolean workflowFaulting, Boolean workflowTerminated, Boolean workflowCanceled, Boolean unlockInstance)<br />
   at <span style="color:#ff0000;">Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.SaveInstanceData</span>(Guid instanceId, Stream instanceStream, DateTime wakeupTime, Boolean bWorkflowCompleted, Boolean bWorkflowSuspended, Boolean bWorkflowFaulting, Boolean bWorkflowTerminated, Boolean bWorkflowCanceled, Boolean unlockInstance)<br />
   at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.Commit(Transaction transaction, ICollection items)<br />
   at System.Workflow.Runtime.WorkBatch.PendingWorkCollection.Commit(Transaction transaction)<br />
   at System.Workflow.Runtime.WorkBatch.Commit(Transaction transaction)<br />
   at System.Workflow.Runtime.VolatileResourceManager.Commit()<br />
   at System.Workflow.Runtime.WorkflowExecutor.DoResourceManagerCommit()<br />
   at System.Workflow.Runtime.Hosting.WorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)<br />
   at <span style="color:#0000ff;"><span style="color:#ff0000;">System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService.CommitWorkBatch</span><span style="color:#000000;">(CommitWorkBatchCallback commitWorkBatchCallback)</span></span></p>
<p><span style="color:#ff0000;">System.Workflow.Runtime Error: 0 : Workflow Runtime: WorkflowExecutor: Persist attempt on instance &#8217;1d973253-8b24-4270-9065-4f3923e87374&#8242; threw an exception &#8216;Transaction (Process ID 152) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.&#8217; <br />
</span>at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)<br />
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)<br />
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)<br />
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)<br />
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)<br />
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)<br />
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)<br />
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)<br />
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()<br />
   at Microsoft.SharePoint.Utilities.SqlSession.ExecuteNonQuery(SqlCommand command)<br />
   at <span style="color:#ff0000;">Microsoft.SharePoint.Workflow.SPWorkflowManager.SaveInstanceData</span>(Guid trackingId, Stream instanceStream, DateTime wakeupTime, Boolean workflowCompleted, Boolean workflowSuspended, Boolean workflowFaulting, Boolean workflowTerminated, Boolean workflowCanceled, Boolean unlockInstance)<br />
   at <span style="color:#ff0000;">Microsoft.SharePoint.Workflow.SPWorkflowHostServiceBase.SaveInstanceData</span>(Guid instanceId, Stream instanceStream, DateTime wakeupTime, Boolean bWorkflowCompleted, Boolean bWorkflowSuspended, Boolean bWorkflowFaulting, Boolean bWorkflowTerminated, Boolean bWorkflowCanceled, Boolean unlockInstance)<br />
   at Microsoft.SharePoint.Workflow.SPWinOePersistenceService.Commit(Transaction transaction, ICollection items)<br />
   at System.Workflow.Runtime.WorkBatch.PendingWorkCollection.Commit(Transaction transaction)<br />
   at System.Workflow.Runtime.WorkBatch.Commit(Transaction transaction)<br />
   at System.Workflow.Runtime.VolatileResourceManager.Commit()<br />
   at System.Workflow.Runtime.WorkflowExecutor.DoResourceManagerCommit()<br />
   at System.Workflow.Runtime.Hosting.WorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)<br />
   at System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)<br />
   at System.Workflow.Runtime.WorkflowExecutor.CommitTransaction(Activity activityContext)<br />
   at <span style="color:#0000ff;"><span style="color:#ff0000;">System.Workflow.Runtime.WorkflowExecutor.Persist</span><span style="color:#000000;">(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sandhoo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sandhoo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sandhoo.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sandhoo.wordpress.com&amp;blog=8619908&amp;post=6&amp;subd=sandhoo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sandhoo.wordpress.com/2009/07/19/sharepoint-workflow-deadlocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00711058af51d518f80c40168b21bfc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Harin</media:title>
		</media:content>
	</item>
	</channel>
</rss>
