<?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>Daniel Larson&#039;s Developer Blog</title>
	<atom:link href="https://daniellarson.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://daniellarson.wordpress.com</link>
	<description>Blogging when I should be working (a developer blog about SharePoint, WCF, AJAX, and life as a Microsoft geek)</description>
	<lastBuildDate>Fri, 18 Nov 2011 20:47:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">17121279</site><cloud domain='daniellarson.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s0.wp.com/i/buttonw-com.png</url>
		<title>Daniel Larson&#039;s Developer Blog</title>
		<link>https://daniellarson.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://daniellarson.wordpress.com/osd.xml" title="Daniel Larson&#039;s Developer Blog" />
	<atom:link rel='hub' href='https://daniellarson.wordpress.com/?pushpress=hub'/>
	<item>
		<title>Step by Step SharePoint Service Applications : Part 4 (Deploying the Solution)</title>
		<link>https://daniellarson.wordpress.com/2011/11/18/step-by-step-sharepoint-service-applications-part-4-deploying-the-solution/</link>
					<comments>https://daniellarson.wordpress.com/2011/11/18/step-by-step-sharepoint-service-applications-part-4-deploying-the-solution/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Fri, 18 Nov 2011 20:47:42 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint service application]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/?p=294</guid>

					<description><![CDATA[This is the fourth post in a series of writing a SharePoint Service Application. As stated in part 3, if you’ve missed the first posts, read those or this won’t make a lick of sense. (It may not make a &#8230; <a href="https://daniellarson.wordpress.com/2011/11/18/step-by-step-sharepoint-service-applications-part-4-deploying-the-solution/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This is the fourth post in a series of writing a SharePoint Service Application. As stated in part 3, if you’ve missed the first posts, read those or this won’t make a lick of sense. (It may not make a lick of sense regardless!) Once again, note that creating a service application is OVERKILL for most things you’ll create for SharePoint<em>. </em>And while this example only spits out a simple “Hello World” type of sample, you can use this as “starter code” for a much more complex application.</p>
<p>For those who attended SharePoint Saturday in Denver last week, here’s the promised code, and thanks for coming to my session! </p>
<p>Here are the first four posts in this series:</p>
<ul>
<li><a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/">Introduction</a>
<li><a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/">Part 1: The Application</a>
<li><a href="https://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/">Part 2: Plumbing</a>
<li><a href="https://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/">Part 3: WCF, The Hard Way</a></li>
</ul>
<p>Now that you have the guts in place, it’s time to create the deployment solution. Whenever you write complex SharePoint solutions, it’s best to keep the SharePoint project that creates the WSP file scoped to the deployment. Think of it ONLY as the Installer project for your SharePoint solution. </p>
<p>Since it’s been a while since I wrote the first posts (I am sorry if you’ve been waiting…), I am going to take the lazy approach here, and post the code for you to download and follow along. Rather than trying to walk you through creating it from scratch, simply download the source and I’ll talk you through the components. </p>
<p><a href="https://skydrive.live.com/?cid=d3543c5837291e93&amp;sc=documents&amp;nl=1&amp;uc=1&amp;id=D3543C5837291E93%2112274#">DOWNLOAD THE SERVICE APPLICATION SOURCE HERE</a> </p>
<p>In the source code you’ll see 2 project: the first is the SuperCoolServiceLibrary. This is the code for the service application, as discussed in the previous posts. The second is the SharePoint “installer” project which we’ll focus on in this post. </p>
<p>The WSP needs to contain the following mapped folder structure:</p>
<ul>
<li>ADMIN (mapped folder <em>{SharePointRoot}\Template\ADMIN</em>)
<ul>
<li>SuperCoolServiceApplication
<ul>
<li>Default.aspx
<li>Manage.aspx</li>
</ul>
</li>
</ul>
<li>Layouts (mapped folder<em> {SharePointRoot}\Template\Layouts</em>)
<ul>
<li>SuperCoolServiceApplication
<ul>
<li>Debug.aspx (just a test page)</li>
</ul>
</li>
</ul>
<li>WebClients (mapped folder <em>{SharePointRoot}\WebClients</em>)
<ul>
<li>SuperCoolServiceApplication
<ul>
<li>Client.config</li>
</ul>
</li>
</ul>
<li>WebServices (mapped folder <em>{SharePointRoot}\WebServices</em>)
<ul>
<li>SuperCoolServiceApplication
<ul>
<li>Web.config
<li>SuperCool.svc</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp; </p>
<p>Let’s start with the most obvious. WebServices contains the WCF web service which will be the backend WCF service. Note that it needs a Web.config file as well as the .svc file. </p>
<p>Next up is WebClients. WebClients contains the client.config file which the configuration based channel factory will use to communicate to the backend service. </p>
<p>Then… the Layouts folder contains just a debug page which will exercise the <em>Hello World</em> method in the service. </p>
<p>Most importantly, you’ll need to include an installer feature which will create the instances and make available your service in the Manage Application Services page. That code looks like this (from <em>installer.eventreceiver.cs</em>):</p>
<pre class="code"><span style="color:blue;">public override void </span>FeatureActivated(<span style="color:#2b91af;">SPFeatureReceiverProperties </span>properties)
{
    <span style="color:#2b91af;">SPFarm </span>farm = <span style="color:#2b91af;">SPFarm</span>.Local;
    <span style="color:#2b91af;">SPServer </span>server = <span style="color:#2b91af;">SPServer</span>.Local;

    <span style="color:green;">// check if the service has already been installed in the farm
    </span><span style="color:blue;">var </span>service = farm.Services.GetValue&lt;<span style="color:#2b91af;">SuperCoolService</span>&gt;();
    <span style="color:blue;">if </span>(service == <span style="color:blue;">null</span>)
    {
        <span style="color:green;">// create the service
        </span>service = <span style="color:blue;">new </span><span style="color:#2b91af;">SuperCoolService</span>(farm);
        service.Status = <span style="color:#2b91af;">SPObjectStatus</span>.Online;
        service.Update();
    }

    <span style="color:green;">// with the service added to the farm, see if there is a installed instance on the server... 
    //   if not, create it
    </span><span style="color:#2b91af;">SuperCoolServiceInstance </span>serverSvcInstance = <span style="color:blue;">new </span><span style="color:#2b91af;">SuperCoolServiceInstance</span>(server, service);
    serverSvcInstance.Update(<span style="color:blue;">true</span>);

    <span style="color:green;">// install the service proxy into the farm if isn't already installed
    </span><span style="color:blue;">var </span>serviceProxy = farm.ServiceProxies.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceProxy</span>&gt;();
    <span style="color:blue;">if </span>(serviceProxy == <span style="color:blue;">null</span>)
    {
        serviceProxy = <span style="color:blue;">new </span><span style="color:#2b91af;">SuperCoolServiceProxy</span>(farm);
        serviceProxy.Update(<span style="color:blue;">true</span>);
    }
}

        
<span style="color:blue;">public override void </span>FeatureDeactivating(<span style="color:#2b91af;">SPFeatureReceiverProperties </span>properties)
{
    <span style="color:#2b91af;">SPFarm </span>farm = <span style="color:#2b91af;">SPFarm</span>.Local;
    <span style="color:#2b91af;">SPServer </span>server = <span style="color:#2b91af;">SPServer</span>.Local;

    <span style="color:green;">//Remove all instances
    </span><span style="color:blue;">var </span>instance = server.ServiceInstances.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceInstance</span>&gt;();
    <span style="color:blue;">while </span>(instance != <span style="color:blue;">null</span>)
    {
        server.ServiceInstances.Remove(instance.Id);
        instance = server.ServiceInstances.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceInstance</span>&gt;();
    }<br><span style="color:green;">    //Uninstall the service proxy
    </span><span style="color:blue;">var </span>serviceProxy = farm.ServiceProxies.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceProxy</span>&gt;();
    <span style="color:blue;">if </span>(serviceProxy != <span style="color:blue;">null</span>)
    {
        farm.ServiceProxies.Remove(serviceProxy.Id);
    }

    <span style="color:green;">//Remove service and jobs
    </span><span style="color:blue;">var </span>service = farm.Services.GetValue&lt;<span style="color:#2b91af;">SuperCoolService</span>&gt;();
    <span style="color:blue;">if </span>(service != <span style="color:blue;">null</span>)            
        farm.Services.Remove(service.Id);
}
</pre>
<p>In the Admin folder, you’ll need a default.aspx page which will be the UI to CREATE an instance of your service application. You can also include an admin page here as well. </p>
<p>The code behind from the default page in Admin contains the following code, which is used to create your service application:</p>
<pre class="code"><span style="color:blue;">var </span>service = <span style="color:#2b91af;">SPFarm</span>.Local.Services.GetValue&lt;<span style="color:#2b91af;">SuperCoolService</span>&gt;();
<span style="color:blue;">if </span>(service == <span style="color:blue;">null</span>)
    <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"The service is not installed."</span>);
                    
<span style="color:green;">//// Get the service proxy object
</span><span style="color:#2b91af;">SuperCoolServiceProxy </span>serviceProxy = <span style="color:#2b91af;">SPFarm</span>.Local.ServiceProxies.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceProxy</span>&gt;();
<span style="color:blue;">if </span>(<span style="color:blue;">null </span>== serviceProxy)
    <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"The service proxy is not installed."</span>);
                    
<span style="color:blue;">var </span>appPoolInput = <span style="color:blue;">this</span>.applicationPoolSection <span style="color:blue;">as </span><span style="color:#2b91af;">IisWebServiceApplicationPoolSection</span>;
<span style="color:blue;">using </span>(<span style="color:#2b91af;">SPLongOperation </span>operation = <span style="color:blue;">new </span><span style="color:#2b91af;">SPLongOperation</span>(<span style="color:blue;">this</span>))
{
    operation.Begin();

    <span style="color:#2b91af;">SPIisWebServiceApplicationPool </span>pool = <span style="color:blue;">null</span>;
    pool = appPoolInput.GetOrCreateApplicationPool();
    <span style="color:blue;">if </span>(pool == <span style="color:blue;">null</span>)
        <span style="color:blue;">throw new </span><span style="color:#2b91af;">ConfigurationErrorsException</span>(<span style="color:#a31515;">"Could not find an application pool to use!!!"</span>);

    <span style="color:blue;">var </span>app = <span style="color:blue;">new </span>SuperCool.ServiceLibrary.<span style="color:#2b91af;">SuperCoolServiceApplication</span>( 
            <span style="color:blue;">this</span>.serviceNameInput.Text, service, pool);

    app.Update(<span style="color:blue;">true</span>);

    app.Provision();

    <span style="color:blue;">var </span>serviceAppProxy = <span style="color:blue;">new </span><span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>(<span style="color:#a31515;">"Super Cool Service Proxy Thingamajig"</span>,
        serviceProxy, app.Uri);
    serviceAppProxy.Provision();
    <span style="color:#2b91af;">SPServiceApplicationProxyGroup</span>.Default.Add(serviceAppProxy);
    <span style="color:#2b91af;">SPServiceApplicationProxyGroup</span>.Default.Update();

    <span style="color:green;">//Start the service instance
    </span><span style="color:blue;">var </span>server = <span style="color:#2b91af;">SPServer</span>.Local;
    <span style="color:blue;">var </span>instance = server.ServiceInstances.GetValue&lt;<span style="color:#2b91af;">SuperCoolServiceInstance</span>&gt;();
    <span style="color:blue;">if </span>(instance == <span style="color:blue;">null</span>) 
    {   <span style="color:green;">//It should be created during feature activation, but if we can't find it  - create it here.
        </span>instance = <span style="color:blue;">new </span><span style="color:#2b91af;">SuperCoolServiceInstance</span>(server, service);
        instance.Update(<span style="color:blue;">true</span>);
    }
    <span style="color:blue;">if </span>(instance != <span style="color:blue;">null </span>&amp;&amp; instance.Status != <span style="color:#2b91af;">SPObjectStatus</span>.Online)
        instance.Provision();
}
<span style="color:blue;">this</span>.SendResponseForPopUI();
</pre>
<p>In case you missed the link, <a href="https://skydrive.live.com/?cid=d3543c5837291e93&amp;sc=documents&amp;nl=1&amp;uc=1&amp;id=D3543C5837291E93%2112274#">DOWNLOAD THE SERVICE APPLICATION SOURCE HERE</a>. Then you can play along!!! I’ll post more notes on this in the coming weeks after the Thanksgiving celebrations die down. </p>
<p>To all of you, Happy Thanksgiving, and may you have a great season of the holy days. </p>
<p>Daniel Larson </p>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2011/11/18/step-by-step-sharepoint-service-applications-part-4-deploying-the-solution/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">294</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>Berthoud Pass 3/5/2011</title>
		<link>https://daniellarson.wordpress.com/2011/03/07/berthoud-pass-352011/</link>
					<comments>https://daniellarson.wordpress.com/2011/03/07/berthoud-pass-352011/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Mon, 07 Mar 2011 16:08:11 +0000</pubDate>
				<category><![CDATA[Berthoud Pass]]></category>
		<category><![CDATA[snowboarding]]></category>
		<category><![CDATA[backcountry]]></category>
		<category><![CDATA[berthoud pass]]></category>
		<category><![CDATA[FOBP]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2011/03/07/berthoud-pass-352011/</guid>

					<description><![CDATA[Saturday was another great day at Berthoud Pass. Our first run up was on the West Side, about an hour hike (it’s probably a whole lot less if you’re not out of shape like I am!) We hit the Meadows &#8230; <a href="https://daniellarson.wordpress.com/2011/03/07/berthoud-pass-352011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Saturday was another great day at Berthoud Pass. Our first run up was on the West Side, about an hour hike (it’s probably a whole lot less if you’re not out of shape like I am!) We hit the Meadows and then down to Current Creek, and then took another lap through the 90s off of the Aqueduct. The snow was great, a pretty stable snowpack with about 9 inches of powder.</p>
<p><a href="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01388.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="DSC01388" src="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01388_thumb.jpg?w=564&#038;h=424" border="0" alt="DSC01388" width="564" height="424" /></a></p>
<p>This time I took a pair of showshoes and a new riding partner, Tony Anzelmo, another .NET developer, and a friend of my last riding partner who STILL HASN’T BOUGHT A BEACON (you know who you are!) Even with a consolidated snowpack, it’s important to have avalanche gear out there. (Thanks to Friends of Berthoud Pass for the avalanche education!)</p>
<p>After lunch, we hit up one last run on Hell’s Half Acre, starting above treeline and down through Hanging Meadow and hit just a little action in Sentinel Chute. I’m not much of a photographer when I ride, but here’s a few pics from some of the slower parts of the day.</p>
<p><a href="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01387.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="DSC01387" src="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01387_thumb.jpg?w=244&#038;h=184" border="0" alt="DSC01387" width="244" height="184" /></a>  <a href="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0368.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="IMAG0368" src="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0368_thumb.jpg?w=302&#038;h=183" border="0" alt="IMAG0368" width="302" height="183" /></a></p>
<p><a href="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0367.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="IMAG0367" src="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0367_thumb.jpg?w=564&#038;h=340" border="0" alt="IMAG0367" width="564" height="340" /></a>  <a href="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0370.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="IMAG0370" src="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0370_thumb.jpg?w=564&#038;h=340" border="0" alt="IMAG0370" width="564" height="340" /></a></p>
<ul>
<li><a href="http://cid-d3543c5837291e93.skydrive.live.com/redir.aspx?page=play&amp;resid=D3543C5837291E93!12253">View the gallery (w/ video)</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2011/03/07/berthoud-pass-352011/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">288</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01388_thumb.jpg" medium="image">
			<media:title type="html">DSC01388</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/dsc01387_thumb.jpg" medium="image">
			<media:title type="html">DSC01387</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0368_thumb.jpg" medium="image">
			<media:title type="html">IMAG0368</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0367_thumb.jpg" medium="image">
			<media:title type="html">IMAG0367</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2011/03/imag0370_thumb.jpg" medium="image">
			<media:title type="html">IMAG0370</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by Step SharePoint Service Applications : Part 3 (WCF, the hard way)</title>
		<link>https://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/</link>
					<comments>https://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Tue, 04 Jan 2011 22:20:33 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[danlarson]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint service application]]></category>
		<category><![CDATA[wcf]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/</guid>

					<description><![CDATA[This is the third post in a series of writing a SharePoint Service Application. If you’ve missed the first posts, read those or this won’t make a lick of sense. (It may not make a lick of sense regardless!) Also &#8230; <a href="https://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This is the third post in a series of writing a SharePoint Service Application. If you’ve missed the first posts, read those or this won’t make a lick of sense. (It may not make a lick of sense regardless!) Also note that creating a service application is OVERKILL for most things you’ll create for SharePoint… this post is NOT “how to write WCF code for SharePoint”, it is <em>VERY SPECIFIC</em> to creating a SharePoint 2010 <em>Managed Service Application. </em>And while this example only spits out a simple “Hello World” sample, you can use this as “starter code” for a much more complex application. </p>
<p>So far, we’ve created the service application library, but no WCF service. In this post, we’ll create the WCF service and a WCF client to call it using the SharePoint application proxy. The WCF client will run on the web front end and will call back to the application server’s instance of the application through your backend web service. In the next post, we’ll cover how to actually deploy the service application in the WSP project. But for now, we’ll just look at the code side of the WCF library. Because we really want to focus on CODE, we won’t cover the WCF configuration stuff quite yet. We’ll take care of that in the WSP project. </p>
<h2>The Service Interface</h2>
<p>As with any WCF service, start with the service interface. Ours will simply return a debug statement—which is actually ideal to include in your production WCF service for debugging support issues. Here is my service interface: </p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.ServiceModel;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Services
{
    <span style="color:gray;">/// &lt;summary&gt;
    /// </span><span style="color:green;">Defines the WCF interface to the backend service application
    </span><span style="color:gray;">/// &lt;/summary&gt;
    /// &lt;remarks&gt;</span><span style="color:green;">Referenced in WebClients\[app name]\client.config</span><span style="color:gray;">&lt;/remarks&gt;
    </span>[<span style="color:#2b91af;">ServiceContract</span>]
<span style="color:blue;">    public interface </span><span style="color:#2b91af;">ICoolService
    </span>{
        [<span style="color:#2b91af;">OperationContract</span>]
        <span style="color:blue;">string </span>GetServiceDebug();
    }
}</pre>
<h2>The Service Class</h2>
<p>For our service implementation, I’ll return some debug info about the call, so you can see what URL it actually gets called on and what identity is calling it. You can also include the attribute [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.NotAllowed)] on this class, since we do NOT support this interface in an ASP.NET context. </p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration.Claims;
<span style="color:blue;">using </span>System.ServiceModel;
<span style="color:blue;">using </span>System.Globalization;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Services
{
    <span style="color:gray;">/// &lt;summary&gt;
    /// </span><span style="color:green;">The actual WCF-callable backend service. (The rest is plumbing)
    </span><span style="color:gray;">/// &lt;/summary&gt;
    </span><span style="color:blue;">public class </span><span style="color:#2b91af;">CoolService </span>: <span style="color:#2b91af;">ICoolService
    </span>{
        <span style="color:green;">// this method would be called as the user.
        </span><span style="color:blue;">public string </span>GetServiceDebug()
        {
            <span style="color:blue;">var </span>encAccountName = 
               <span style="color:#2b91af;">SPClaimProviderManager</span>.Local.GetUserIdentifierEncodedClaim(
               <span style="color:#2b91af;">ServiceSecurityContext</span>.Current.PrimaryIdentity);
            <span style="color:blue;">var </span>claimsAccountName = 
               <span style="color:#2b91af;">SPClaimProviderManager</span>.Local.ConvertClaimToIdentifier(encAccountName);

            <span style="color:green;">// you can also use System.Threading.Thread.CurrentPrincipal.Identity

            </span><span style="color:#2b91af;">SPIisWebServiceApplication </span>current = <span style="color:#2b91af;">SPIisWebServiceApplication</span>.Current;

            <span style="color:blue;">return string</span>.Format(<span style="color:#2b91af;">CultureInfo</span>.InvariantCulture, 
                <span style="color:#a31515;">@"Hello, {0}. So glad you used ""{1}"" (a {2}, id {3}) at {4}."</span>,
                claimsAccountName,
                current.DisplayName,
                current.GetType().Name,
                current.Id,
               <span style="color:#2b91af;">OperationContext</span>.Current.IncomingMessageProperties[
               <span style="color:#a31515;">"OriginalHttpRequestUri"</span>]               
                );
        }
    }
}

</pre>
<p>&nbsp;</p>
<p>This backend service will ALWAYS be authenticated by claims authentication—it is the delegation used by SharePoint, which we’ll configure in the client in the next code sample. The ServiceSecurityContext.Current.PrimaryIdentity will be a ClaimsIdentity, which you can get the current user from. To get the current User Profile from the backend service, you can use this claims identity to get the user profile from the User Profile application (it will use the User Profile Application that is in the same proxy group as your application). </p>
<pre class="code"><span style="color:blue;">private </span>UserProfile GetDelegatedIdentityProfile()
{
   <span style="color:blue;">var </span>encAccountName = 
      SPClaimProviderManager.Local.GetUserIdentifierEncodedClaim(
      <span style="color:#2b91af;">ServiceSecurityContext</span>.Current.PrimaryIdentity); 
   <span style="color:blue;">var </span>claimsAccountName = 
      SPClaimProviderManager.Local.ConvertClaimToIdentifier(encAccountName);
   <span style="color:blue;">var </span>um = <span style="color:blue;">new </span>UserProfileManager(<span style="color:#2b91af;">SPServiceContext</span>.Current, <span style="color:blue;">false</span>, <span style="color:blue;">false</span>);
   <span style="color:blue;">return </span>um.GetUserProfile(claimsAccountName, <span style="color:blue;">false</span>);
} </pre>
<h3>Getting the Service Application from your WCF Code</h3>
<p>Within your service, there is a MAGIC property that you can use to get the instance of your application. SPIisWebServiceApplication.Current will return the current application that your service is created under. Note that you can create multiple instances of the service on the Central Administration “Manage Service Applications” page, each of which could have it’s own persisted data, database connections and more. This magic property is the only thing that ties your WCF class to your service application! In the smaple code above, you’ll see that we’re simply writing out the name and id of the application. </p>
<h2>Calling the Backend through a Service Client </h2>
<p>The last part of the plumbing is creating an actual service client. With “sane” WCF programming, you usually let Visual Studio do this type of thing for you. Not so in this case however, you’ve got to do a lot to the channel with credentials and dynamic, load-balanced endpoint URLs. </p>
<p>Most of this is “boilerplate” code that uses the SharePoint load balancer to call the application servers. <em>To scale out your application, be sure the service instance is running on multiple app servers. You’ll need to start it on the “Services on Server” page (well, after you create the WCF project, which we’ll do in the next post!).</em> The client will use the ConfigurationChannelFactory and the proxy’s configuration which we’ll deploy in the WSP project in order to configure itself. Specifically, the channel factory will call SuperCoolServiceApplicationProxy.Configuration to read the configuration for the client. We previously defined this as:</p>
<pre class="code"><span style="color:blue;">internal </span><span style="color:#2b91af;">Configuration </span>Configuration
{
    <span style="color:blue;">get
    </span>{
        <span style="color:blue;">return </span>OpenClientConfiguration(<span style="color:#2b91af;">SPUtility</span>.GetGenericSetupPath(
            <span style="color:#a31515;">@"WebClients\SuperCoolServiceApplication"</span>));
    }
}</pre>
<p>Following is a client class that contains the infrastructure to call the backend service. You could make this into a common base class, but I’ll keep it simple to get the concept across. The main methods to look at are “ExecuteOnChannel” and GetChannel. After that, just implement the interface of your service, and use ExecuteOnChannel to call the backend service. </p>
<pre class="code"><span style="color:blue;">using </span>SuperCool.ServiceLibrary.Services;
<span style="color:blue;">using </span>Microsoft.SharePoint;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;
<span style="color:blue;">using </span>System.ServiceModel;
<span style="color:blue;">using </span>System.ServiceModel.Channels;
<span style="color:blue;">using </span>System.ServiceModel.Configuration;
<span style="color:blue;">using </span>System;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Client
{
   <span style="color:gray;">/// &lt;summary&gt;
   /// </span><span style="color:green;">A WCF client for talking through the WCF channel to the backend. 
   </span><span style="color:gray;">/// &lt;/summary&gt;
   </span><span style="color:blue;">public class </span><span style="color:#2b91af;">SuperCoolClient </span>: <span style="color:#2b91af;">ICoolService
   </span>{
      <span style="color:blue;">private </span><span style="color:#2b91af;">SPServiceContext </span>serviceContext;

      <span style="color:blue;">public </span>SuperCoolClient() : <span style="color:blue;">this</span>(<span style="color:blue;">null</span>) { }
      <span style="color:blue;">public </span>SuperCoolClient(<span style="color:#2b91af;">SPServiceContext </span>serviceContext)
      {
         <span style="color:blue;">if </span>(serviceContext == <span style="color:blue;">null</span>)
         {
            <span style="color:blue;">if </span>(<span style="color:#2b91af;">SPServiceContext</span>.Current != <span style="color:blue;">null</span>)
               serviceContext = <span style="color:#2b91af;">SPServiceContext</span>.Current;
            <span style="color:blue;">else
               this</span>.serviceContext = <span style="color:#2b91af;">SPServiceContext</span>.GetContext(
                   <span style="color:#2b91af;">SPServiceApplicationProxyGroup</span>.Default,
                   <span style="color:blue;">new </span><span style="color:#2b91af;">SPSiteSubscriptionIdentifier</span>(<span style="color:#2b91af;">Guid</span>.Empty));
         }
         <span style="color:blue;">else
            this</span>.serviceContext = serviceContext;

         <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.serviceContext == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentNullException</span>(<span style="color:#a31515;">"serviceContext"</span>);
      }

      <span style="color:blue;">private delegate void </span><span style="color:#2b91af;">CodeToExecuteOnChannel</span>(<span style="color:#2b91af;">ICoolService </span>channel);

      <span style="color:blue;">private void </span>ExecuteOnChannel(<span style="color:#2b91af;">CodeToExecuteOnChannel </span>codeBlock, 
         <span style="color:blue;">bool </span>asProcess)
      {
         <span style="color:blue;">if </span>(codeBlock == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentNullException</span>(<span style="color:#a31515;">"codeBlock"</span>);
         <span style="color:#2b91af;">SuperCoolServiceApplicationProxy </span>proxy = 
            (<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>)
            <span style="color:blue;">this</span>.serviceContext.GetDefaultProxy(
            <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>));

         <span style="color:blue;">if </span>(proxy == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"service proxy not found."</span>);

         <span style="color:#2b91af;">SPServiceLoadBalancer </span>loadBalancer = proxy.LoadBalancer;
         <span style="color:blue;">if </span>(loadBalancer == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">"load balancer not found."</span>);

         <span style="color:#2b91af;">SPServiceLoadBalancerContext </span>loadBalancerContext = 
            loadBalancer.BeginOperation();
         <span style="color:blue;">try
         </span>{
            <span style="color:blue;">using </span>(<span style="color:blue;">new </span><span style="color:#2b91af;">SPServiceContextScope</span>(<span style="color:blue;">this</span>.serviceContext))
            {
               <span style="color:green;">// Get a channel to the service application endpoint
               </span><span style="color:#2b91af;">IChannel </span>channel = (<span style="color:#2b91af;">IChannel</span>)GetChannel(proxy,
                   loadBalancerContext.EndpointAddress, asProcess);
               <span style="color:blue;">try
               </span>{
                  <span style="color:green;">// Execute the delegate
                  </span>codeBlock((<span style="color:#2b91af;">ICoolService</span>)channel);

                  <span style="color:green;">// Close the channel
                  </span>channel.Close();
               }
               <span style="color:blue;">finally
               </span>{
                  <span style="color:blue;">if </span>(channel.State != <span style="color:#2b91af;">CommunicationState</span>.Closed)
                     channel.Abort();
               }
            }
         }
         <span style="color:blue;">catch </span>(<span style="color:#2b91af;">EndpointNotFoundException</span>)
         {
            loadBalancerContext.Status = <span style="color:#2b91af;">SPServiceLoadBalancerStatus</span>.Failed;
            <span style="color:blue;">throw</span>;
         }
         <span style="color:blue;">finally
         </span>{
            loadBalancerContext.EndOperation();
         }
      }

      <span style="color:green;">// Used to cache the client channel factory
      </span><span style="color:blue;">private static </span><span style="color:#2b91af;">ChannelFactory</span>&lt;<span style="color:#2b91af;">ICoolService</span>&gt; s_ChannelFactory;
      <span style="color:blue;">private static object </span>s_ChannelFactoryLock = <span style="color:blue;">new object</span>();

      <span style="color:blue;">private </span><span style="color:#2b91af;">ICoolService </span>GetChannel(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy </span>proxy,
          <span style="color:#2b91af;">Uri </span>address, <span style="color:blue;">bool </span>asProcess)
      {
         <span style="color:blue;">if </span>(proxy == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentNullException</span>(<span style="color:#a31515;">"proxy"</span>);

         <span style="color:blue;">if </span>(address == <span style="color:blue;">null</span>)
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentNullException</span>(<span style="color:#a31515;">"address"</span>);

         <span style="color:green;">// Check for a cached channel factory
         </span><span style="color:blue;">if </span>(s_ChannelFactory == <span style="color:blue;">null</span>)
         {
            <span style="color:blue;">lock </span>(s_ChannelFactoryLock)
            {
               <span style="color:blue;">if </span>(s_ChannelFactory == <span style="color:blue;">null</span>)
               {
                  s_ChannelFactory = 
                     <span style="color:blue;">new </span><span style="color:#2b91af;">ConfigurationChannelFactory</span>&lt;<span style="color:#2b91af;">ICoolService</span>&gt;(
                     <span style="color:#a31515;">"https"</span>, proxy.Configuration, <span style="color:blue;">null</span>);

                  <span style="color:green;">// Configure the channel factory for claims-based auth
                  </span>s_ChannelFactory.ConfigureCredentials(
                     <span style="color:#2b91af;">SPServiceAuthenticationMode</span>.Claims);
               }
            }
         }
         <span style="color:blue;">if </span>(asProcess)
            <span style="color:blue;">return </span>s_ChannelFactory.CreateChannelAsProcess(
               <span style="color:blue;">new </span><span style="color:#2b91af;">EndpointAddress</span>(address));
         <span style="color:blue;">else
            return </span>s_ChannelFactory.CreateChannelActingAsLoggedOnUser(
               <span style="color:blue;">new </span><span style="color:#2b91af;">EndpointAddress</span>(address));
      }

      <span style="color:blue;">public string </span>GetServiceDebug()
      {
         <span style="color:blue;">string </span>result = <span style="color:blue;">null</span>;
         <span style="color:blue;">this</span>.ExecuteOnChannel(
            channel =&gt; result = channel.GetServiceDebug(), asProcess: <span style="color:blue;">false</span>);
         <span style="color:blue;">return </span>result;
      }
   }
}</pre>
<p>Also note that ExecuteOnChannel takes an “asProcess” parameter—we will either create the channel as the logged in user and configure the SharePoint claim to delegate, or we’ll delegate the current process identity. </p>
<p>The last piece is a ServiceHostFactory. There’s not too much to this, but you’ve got to use a custom host factory to configure claims authentication. We’ll reference this class in the .SVC file. Not sure why there isn’t one of these that SharePoint ships, or maybe there is one that I’m missing… but for some reason you have to do this to wire up the backend WCF endpoint. There’s nothing special about this class for our application.</p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.ServiceModel.Activation;
<span style="color:blue;">using </span>System.ServiceModel;
<span style="color:blue;">using </span>Microsoft.SharePoint;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Services
{
    <span style="color:blue;">internal sealed class </span><span style="color:#2b91af;">SuperCoolHostFactory</span>: <span style="color:#2b91af;">ServiceHostFactory
    </span>{
        <span style="color:blue;">public override </span><span style="color:#2b91af;">ServiceHostBase </span>CreateServiceHost(
           <span style="color:blue;">string </span>constructorString, <span style="color:#2b91af;">Uri</span>[] baseAddresses)
        {
            <span style="color:#2b91af;">ServiceHostBase </span>serviceHost = <span style="color:blue;">base</span>.CreateServiceHost(
               constructorString, baseAddresses);
            serviceHost.Configure(<span style="color:#2b91af;">SPServiceAuthenticationMode</span>.Claims);
            <span style="color:blue;">return </span>serviceHost;
        }
    }
}</pre>
<p>With the WCF interface, service and client in place, we’re now ready to deploy the service application in a WSP project. We’ll do that next… stay tuned! (And I promise, I’ll post the whole source code for this… ) </p>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2011/01/04/step-by-step-sharepoint-service-applications-part-3-wcf/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">275</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by Step SharePoint Service Applications : Part 2 (Plumbing)</title>
		<link>https://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/</link>
					<comments>https://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Thu, 16 Dec 2010 18:36:04 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/</guid>

					<description><![CDATA[Read the previous posts in this series: Intro, Part 1 In the previous post, we looked at a simple SPIisWebServiceApplication. The SPIisWebServiceApplication is the “instance” of your application that gets provisioned and is managed in Central Administration. It “has” things &#8230; <a href="https://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p><em>Read the previous posts in this series: </em><a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/"><em>Intro</em></a><em>, </em><a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/"><em>Part 1</em></a></p>
<p>In the previous post, we looked at a simple <a href="SPIisWebServiceApplication">SPIisWebServiceApplication</a>. The SPIisWebServiceApplication is the “instance” of your application that gets provisioned and is managed in Central Administration. It “has” things like the database, jobs and persisted storage associated with it. Soon we’ll add a WCF service which web front end code (and remote farms!) can talk to it with. But before we’ll be able to create the application, we’ll need to define the “Create” links to it in the SharePoint infrastructure. We’ll need a service, a service instance, and then we’ll need a proxy and application proxy in order to talk to it. In this post we’ll focus on these components—they are simple “infrastructure” components without anything super-fancy.</p>
<p>The following class is used to create a menu-item for creating a new Service Application on the Manage Service Applications page. Really the only thing you need to edit is the GetApplicationTypeDescription method and the GetCreateApplicationLink method. The rest is “plumbing” code which you really don’t need to change. </p>
<p>Also note that each of these classes has a Guid attribute. Put a Guid attribute on each “Infrastructure” class for the service application. These generally aren’t referenced, but you’ll need to reference the SPIisWebServiceApplication’s GUID in it’s proxy class.&nbsp; </p>
<p>In the service library project, the following SPIIsWebService class creates the link to creating a new Super Cool Service application. As I mentioned, there’s nothing spectacular about this code. It’s just used to create the link.</p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;
<span style="color:blue;">using </span>System.Runtime.InteropServices;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary
{
    <span style="color:gray;">/// &lt;summary&gt;
    /// </span><span style="color:green;">The service plumbing-- the thing that's creatable from Central Admin.
    </span><span style="color:gray;">/// &lt;/summary&gt;
    </span>[<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"6810AFD9-3137-4bc2-8AF1-00EB8461A861"</span>)]<span style="color:green;">// arbitrary GUID, not referenced in code. 
    </span><span style="color:blue;">public sealed class </span><span style="color:#2b91af;">SuperCoolService </span>: <span style="color:#2b91af;">SPIisWebService</span>, <span style="color:#2b91af;">IServiceAdministration
    </span>{
        <span style="color:blue;">public </span>SuperCoolService() { }
        <span style="color:blue;">public </span>SuperCoolService(<span style="color:#2b91af;">SPFarm </span>farm): <span style="color:blue;">base</span>(farm) { }

        <span style="color:#2b91af;">Type</span>[] <span style="color:#2b91af;">IServiceAdministration</span>.GetApplicationTypes()
        {
            <span style="color:blue;">return new </span><span style="color:#2b91af;">Type</span>[] { <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplication</span>) };
        }

        <span style="color:#2b91af;">SPPersistedTypeDescription IServiceAdministration</span>.GetApplicationTypeDescription(<br>            <span style="color:#2b91af;">Type </span>serviceApplicationType)
        {
            <span style="color:blue;">if </span>(serviceApplicationType != <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplication</span>))
            {
                <span style="color:blue;">throw new </span><span style="color:#2b91af;">NotSupportedException</span>();
            }

            <span style="color:blue;">return new </span><span style="color:#2b91af;">SPPersistedTypeDescription</span>(
                <span style="color:#a31515;">"Super Cool Service"</span>,
                <span style="color:#a31515;">"A super cool service application for managing super cool things."</span>);
        }

        <span style="color:blue;">public override </span><span style="color:#2b91af;">SPAdministrationLink </span>GetCreateApplicationLink(<span style="color:#2b91af;">Type </span>serviceApplicationType)
        {
            <span style="color:blue;">return new </span><span style="color:#2b91af;">SPAdministrationLink</span>(<span style="color:#a31515;">"/_admin/SuperCoolServiceApplication/default.aspx"</span>);
        }

        <span style="color:blue;">public override </span><span style="color:#2b91af;">SPCreateApplicationOptions </span>GetCreateApplicationOptions(<br>            <span style="color:#2b91af;">Type </span>serviceApplicationType)
        {
            <span style="color:blue;">return </span><span style="color:#2b91af;">SPCreateApplicationOptions</span>.None;
        }

        <span style="color:#2b91af;">SPServiceApplication IServiceAdministration</span>.CreateApplication(
            <span style="color:blue;">string </span>name, <span style="color:#2b91af;">Type </span>serviceApplicationType, 
            <span style="color:#2b91af;">SPServiceProvisioningContext </span>provisioningContext)
        {
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">NotSupportedException</span>();
        }

        <span style="color:#2b91af;">SPServiceApplicationProxy IServiceAdministration</span>.CreateProxy(
            <span style="color:blue;">string </span>name, <span style="color:#2b91af;">SPServiceApplication </span>serviceApplication, 
            <span style="color:#2b91af;">SPServiceProvisioningContext </span>provisioningContext)
        {
            <span style="color:blue;">throw new </span><span style="color:#2b91af;">NotSupportedException</span>();
        }
    }
} </pre>
<p>The next class you’ll need is the SPIisWebServiceInstance class. This isn’t really used for anything but letting SharePoint define which service runs on each server. Nothing spectacular here, and the only thing you really need to specify is the name. </p>
<pre class="code"><span style="color:blue;">using </span>System.Runtime.InteropServices;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary
{
    [<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"0EBCD546-373C-4c1e-83BD-1D3B504F3E98"</span>)]
    <span style="color:blue;">public class </span><span style="color:#2b91af;">SuperCoolServiceInstance </span>: <span style="color:#2b91af;">SPIisWebServiceInstance
    </span>{
        <span style="color:blue;">public </span>SuperCoolServiceInstance() { }
        <span style="color:blue;">public </span>SuperCoolServiceInstance(<span style="color:#2b91af;">SPServer </span>server, <span style="color:#2b91af;">SuperCoolService </span>service)
            : <span style="color:blue;">base</span>(server, service) { }
                
        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets the display name for the administrative UI.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">public override string </span>TypeName
        {
            <span style="color:blue;">get </span>{ <span style="color:blue;">return </span><span style="color:#a31515;">"Super-Duper Super-Cool Service"</span>; }
        }
    }
}</pre>
<p>That’s it for Service classes. Now we’ll need to add Proxy classes, which are used by the front end to talk to the backend. These are relatively simple classes too, nothing but plumbing. </p>
<p>The SPIisWebServiceProxy is used to connect to the service application. This isn’t the ACTUAL application proxy, just the “glue” to tie the application proxy to the service. It needs bi-directional references with the SPIisWebServiceApplicationProxy, so if you’re writing your own create your own subclasses of SPIisWebServiceProxy and SPIisWebServiceApplicationProxy at this time. My classes will be called SuperCoolServiceProxy and SuperCoolServiceApplicationProxy.</p>
<p>First, the SPIisWebServiceProxy is used to connect the proxies to the service. The important thing here though is that you need to reference the service application’s Guid that this supports. This is the magic that lets it work… without matching Guids in the <span style="color:#2b91af;">SupportedServiceApplication</span> attribute it’s not going to work. The rest is self-explanatory, just copy the following code and refactor it for your app. </p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;
<span style="color:blue;">using </span>System.Runtime.InteropServices;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Client
{
    [<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"4DE3E259-EC52-4841-9D5B-B9A3AA095B51"</span>)]
    [<span style="color:#2b91af;">SupportedServiceApplication</span>(<span style="color:#a31515;">"12A1BE54-04E7-4457-B8FE-6E11647E7EA6"</span>, 
        <span style="color:#a31515;">"1.0.0.0"</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>))]   
    <span style="color:blue;">public class </span><span style="color:#2b91af;">SuperCoolServiceProxy </span>: <span style="color:#2b91af;">SPIisWebServiceProxy</span>, <span style="color:#2b91af;">IServiceProxyAdministration
    </span>{
        <span style="color:blue;">public </span>SuperCoolServiceProxy() { }
        <span style="color:blue;">public </span>SuperCoolServiceProxy(<span style="color:#2b91af;">SPFarm </span>farm) : <span style="color:blue;">base</span>(farm) { }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets an array of the service application proxy types supported by the service proxy.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:#2b91af;">Type</span>[] <span style="color:#2b91af;">IServiceProxyAdministration</span>.GetProxyTypes()
        {
            <span style="color:blue;">return new </span><span style="color:#2b91af;">Type</span>[] { <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>) };
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets a description of the specified service application proxy type.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name="serviceApplicationProxyType"&gt;</span><span style="color:green;">The service application proxy type.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;returns&gt;</span><span style="color:green;">A description of the specified type suitable for display.</span><span style="color:gray;">&lt;/returns&gt;
        </span><span style="color:#2b91af;">SPPersistedTypeDescription IServiceProxyAdministration</span>.GetProxyTypeDescription(
            <span style="color:#2b91af;">Type </span>serviceApplicationProxyType)
        {
            <span style="color:blue;">if </span>(serviceApplicationProxyType != <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>))
                <span style="color:blue;">throw new </span><span style="color:#2b91af;">NotSupportedException</span>();

            <span style="color:blue;">return new </span><span style="color:#2b91af;">SPPersistedTypeDescription</span>(
                <span style="color:#a31515;">"Super-Duper Super Cool Service Proxy"</span>,
                <span style="color:#a31515;">"Connects to a Super Cool Service Application for managing super cool things."</span>);
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Creates an instance of the specified service application proxy type.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name="serviceApplicationProxyType"&gt;</span><span style="color:green;">The type of proxy to create.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name="name"&gt;</span><span style="color:green;">The name of the new proxy.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name="serviceApplicationUri"&gt;</span><span style="color:green;">The address of the connected service application.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name="provisioningContext"&gt;</span><span style="color:green;">Context for the provisioning operation.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </span><span style="color:#2b91af;">SPServiceApplicationProxy IServiceProxyAdministration</span>.CreateProxy(
            <span style="color:#2b91af;">Type </span>serviceApplicationProxyType, <span style="color:blue;">string </span>name, <span style="color:#2b91af;">Uri </span>serviceApplicationUri, <br>            <span style="color:#2b91af;">SPServiceProvisioningContext </span>provisioningContext)
        {
            <span style="color:blue;">if </span>(serviceApplicationProxyType != <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>))
                <span style="color:blue;">throw new </span><span style="color:#2b91af;">NotSupportedException</span>();

            <span style="color:blue;">return new </span><span style="color:#2b91af;">SuperCoolServiceApplicationProxy</span>(name, <span style="color:blue;">this</span>, serviceApplicationUri);
        }
    }
}

</pre>
<p>&nbsp;</p>
<p>Next, the ACTUAL code that is the proxy is responsible for setting up the load balancer and reading the client configuration. You’re going to want to scale your service application across multiple app servers—we need redundancy for our Hello World service app!!! But again, the code is relatively simple. You should be able to refactor the following code without effort. Following is a simple implementation of the SPIisWebServiceApplicationProxy. Next to the SPIisWebServiceApplication class, this is the next most important piece of the puzzle. There isn’t TOO much in here though, we’ll actually code much of the proxy logic into the client. </p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>Microsoft.SharePoint.Administration;
<span style="color:blue;">using </span>Microsoft.SharePoint;
<span style="color:blue;">using </span>System.Configuration;
<span style="color:blue;">using </span>Microsoft.SharePoint.Utilities;
<span style="color:blue;">using </span>SuperCool.ServiceLibrary.Services;

<span style="color:blue;">namespace </span>SuperCool.ServiceLibrary.Client
{
    [System.Runtime.InteropServices.<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"D49DF84A-77E3-47f9-85D3-965FA3D9E305"</span>)]
    [<span style="color:#2b91af;">IisWebServiceApplicationProxyBackupBehavior</span>]
    <span style="color:blue;">public class </span><span style="color:#2b91af;">SuperCoolServiceApplicationProxy </span>: <span style="color:#2b91af;">SPIisWebServiceApplicationProxy
    </span>{
        [<span style="color:#2b91af;">Persisted</span>]
        <span style="color:blue;">private </span><span style="color:#2b91af;">SPServiceLoadBalancer </span>loadBalancer;
        <span style="color:blue;">public </span>SuperCoolServiceApplicationProxy(){}

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Constructs a new service application proxy.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name="name"&gt;</span><span style="color:green;">The name of the new service application proxy.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name="serviceProxy"&gt;</span><span style="color:green;">The parent service proxy.</span><span style="color:gray;">&lt;/param&gt;
        /// &lt;param name="serviceApplicationAddress"&gt;
        /// </span><span style="color:green;">The URI of the service application to which the new proxy will connect.</span><span style="color:gray;">&lt;/param&gt;
        </span><span style="color:blue;">public </span>SuperCoolServiceApplicationProxy(<span style="color:blue;">string </span>name, <span style="color:#2b91af;">SuperCoolServiceProxy </span>serviceProxy, 
            <span style="color:#2b91af;">Uri </span>serviceApplicationAddress)
            : <span style="color:blue;">base</span>(name, serviceProxy, serviceApplicationAddress)
        {
            <span style="color:green;">// Create a new round-robin load balancer
            </span><span style="color:blue;">this</span>.loadBalancer = <span style="color:blue;">new </span><span style="color:#2b91af;">SPRoundRobinServiceLoadBalancer</span>(serviceApplicationAddress);
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets the display name that describes the object in the admin UI
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">public override string </span>TypeName
        {
            <span style="color:blue;">get </span>{ <span style="color:blue;">return </span><span style="color:#a31515;">"Super Cool Application Proxy"</span>; }
        }

        <span style="color:blue;">public override void </span>Provision()
        {
            <span style="color:blue;">this</span>.loadBalancer.Provision();
            <span style="color:blue;">base</span>.Provision();
        }

        <span style="color:blue;">public override void </span>Unprovision(<span style="color:blue;">bool </span>deleteData)
        {
            <span style="color:green;">// Unprovision the load balancer
            </span><span style="color:blue;">this</span>.loadBalancer.Unprovision();
            <span style="color:blue;">base</span>.Unprovision(deleteData);
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets the load balancer used by the service application proxy.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">internal </span><span style="color:#2b91af;">SPServiceLoadBalancer </span>LoadBalancer
        {
            <span style="color:blue;">get
            </span>{
                <span style="color:blue;">return this</span>.loadBalancer;
            }
        }

        <span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">Gets the configuration used by the service application proxy.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">internal </span><span style="color:#2b91af;">Configuration </span>Configuration
        {
            <span style="color:blue;">get
            </span>{
                <span style="color:blue;">return </span>OpenClientConfiguration(<span style="color:#2b91af;">SPUtility</span>.GetGenericSetupPath(
                    <span style="color:#a31515;">@"WebClients\SuperCoolServiceApplication"</span>));
            }
        }
    }
}</pre>
<p>With those classes, SPIisWebServiceApplication (covered in the last post), SPIisWebService, SPIisWebServiceInstance, SPIisWebServiceProxy and SPIisWebServiceApplicationProxy, we’ve got the SharePoint plumbing part of our service application library completed. Nothing too complex, but a lot of redundant code. In the next post, we’ll create our Hello World WCF service and we’ll cover the WCF plumbing, and then we’ll look at deploying it in the WSP project. After that, we’ll circle back and talk about databases and timer jobs within the service application framework.</p>
<p><em><font size="2">About Daniel Larson: </font></em><font size="2">I am a SharePoint Architect at </font><a href="http://www.newsgator.com/"><font size="2">NewsGator</font></a><font size="2">, (<em>the</em> Social Platform for SharePoint 2010) and author of the best-selling Microsoft Press books </font><a href="http://www.amazon.com/Microsoft-Windows-SharePoint-Services-Developer/dp/0735623201"><font size="2">Inside Microsoft Windows SharePoint Services 3.0</font></a><font size="2"> (with Ted Pattison) and </font><a href="http://www.amazon.com/Developing-Service-Oriented-Applications-Microsoft-PRO-Developer/dp/0735625913/"><font size="2">Developing Service-Oriented AJAX Applications</font></a><font size="2">. </font></p>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/12/16/step-by-step-sharepoint-service-applications-part-2-plumbing/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">273</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by Step SharePoint Service Applications : Part 1</title>
		<link>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/</link>
					<comments>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Tue, 14 Dec 2010 18:09:53 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/</guid>

					<description><![CDATA[If you missed the intro, check it out for some background on WHY you’d want to create a backend service library for SharePoint 2010. (Read it here!) It really isn’t for everyone—but if you’re creating enterprise scale applications for SharePoint &#8230; <a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>If you missed the intro, check it out for some background on WHY you’d want to create a backend service library for SharePoint 2010. <a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/">(Read it here!)</a> It really isn’t for everyone—but if you’re creating enterprise scale applications for SharePoint 2010, the service architecture/framework is the right way to scale out your application. </p>
<p>To get stated, create a Class Library called “SuperCool.ServiceLibrary”. This will be the backend service library, and will also contain the proxy classes and client proxy. </p>
<p>At the heart of the service library is the <a href="SPIisWebServiceApplication">SPIisWebServiceApplication</a>. This class is your application instance, but it is NOT the backend WCF service that you will call. (We’ll cover that later.) This object is persisted in the Config database, and holds references to the WCF endpoints it serves as well as any databases you create. It will also be responsible for provisioning any jobs you define for your application. </p>
<p>The first three methods are what points the application to your backend WCF service (that we haven’t written yet), so you can ignore those for now but you’ve got to include them. The rest is pretty much boilerplate code, it sets up the application plumbing. </p>
<table border="1" cellspacing="0" cellpadding="2" width="952">
<tbody>
<tr>
<td valign="top" width="950">
<p><font size="2" face="Consolas">using System;<br />using System.Collections.Generic;<br />using Microsoft.SharePoint.Administration;<br />using Microsoft.SharePoint.Utilities;<br />using Microsoft.SharePoint;</font></p>
<p><font size="2" face="Consolas">namespace SuperCool.ServiceLibrary<br />{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp; /// The conceptual service application.&nbsp; <br />&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp; // This magic GUID is used to define the service application and match it with supported proxies<br />&nbsp;&nbsp;&nbsp; [System.Runtime.InteropServices.Guid(&#8220;ACE7BB07-1891-46e0-A7DD-0B23CD7ED90D&#8221;)]<br />&nbsp;&nbsp;&nbsp; [IisWebServiceApplicationBackupBehavior]<br />&nbsp;&nbsp;&nbsp; public class SuperCoolServiceApplication : SPIisWebServiceApplication<br />&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override string VirtualPath<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { get{ return &#8220;SuperCool.svc&#8221;; } }</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override string DefaultEndpointName<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { get { return &#8220;https&#8221;; } }</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected override string InstallPath<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get {return SPUtility.GetGenericSetupPath(@&#8221;WebServices\SuperCoolServiceApplication&#8221;); }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Target location admin is sent to from within CA when clicking on Service App or <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// selecting it and picking Manage in the ribbon from CA &gt; Manage Service Apps page.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override SPAdministrationLink ManageLink<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return new SPAdministrationLink(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;/_admin/SuperCoolServiceApplication/Manage.aspx?ApplicationId=&#8221; + this.Id.ToString(&#8220;N&#8221;)); }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public SuperCoolServiceApplication(){}</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public SuperCoolServiceApplication(string name, SPIisWebService service, SPIisWebServiceApplicationPool applicationPool)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : base(name, service, applicationPool){}</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override void Provision()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.Provision();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.Id == Guid.Empty)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Update();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegisterEndpoint(this, &#8220;https&#8221;, SPIisWebServiceBindingType.Https, &#8220;secure&#8221;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.Service.Status != SPObjectStatus.Online)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.Service.Provision();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Service.Status = SPObjectStatus.Online;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Service.Update();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Status = SPObjectStatus.Online;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Update();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override void Unprovision(bool deleteData)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (SPIisWebServiceEndpoint ep in this.Endpoints)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ep.Delete();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.Unprovision(deleteData);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static void RegisterEndpoint(SPIisWebServiceApplication serviceApplication, string name, SPIisWebServiceBindingType binding, string relativeAddress)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (SPIisWebServiceEndpoint endpoint in serviceApplication.Endpoints)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (endpoint.Name == name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font size="2" face="Consolas">if (!string.IsNullOrEmpty(relativeAddress))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceApplication.AddServiceEndpoint(name, binding, relativeAddress);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; serviceApplication.AddServiceEndpoint(name, binding);<br /></font><font size="2" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}</font></p>
</td>
</tr>
</tbody>
</table>
<p>The Provision method is the main method that sets things up. This method registers the endpoints, and is also where you’d provision any databases, jobs or additional resources that will be “owned” by the service application. </p>
<p>With that one class, we’ve got the guts of Service Application created. In the next few posts we’ll look at creating the service instance, the service proxy and client, and we’ll wire it up through the SharePoint solution. </p>
<p>(Where are we going with this? This will just be a sample app that spits out “hello, world”. But it’ll have a backend database and be centrally managed. I’ll leave it to you to come up with something interesting, something super-cool to add to this!!!) </p>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">269</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>Step by Step SharePoint Service Applications: Intro</title>
		<link>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/</link>
					<comments>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/#comments</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Tue, 14 Dec 2010 17:59:39 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/</guid>

					<description><![CDATA[In the following blog posts, I’ll be focusing on writing custom service applications for SharePoint 2010. Service Applications are shared services that are managed in Central Administration that can be consumed by the local or remote farms. Service applications can &#8230; <a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>In the following blog posts, I’ll be focusing on writing custom service applications for SharePoint 2010. Service Applications are shared services that are managed in Central Administration that can be consumed by the local or remote farms. Service applications can include a WCF backend service, timer jobs, custom database(s), permissions and central administration management. </p>
<p>For trivial web part applications, a Service Application is overkill. But to move your application to a <em>service-based</em> architecture that can be consumed across the enterprise (by SharePoint farms, that is…) then you should consider a Service Application. </p>
<p>Reasons to write a service application:</p>
<ol>
<li>You need a custom database
<li>You need Central Administration of your application
<li>You want to publish your application services to multiple web applications
<li>You want to publish your application services to multiple SharePoint farms</li>
</ol>
<p>Probable the best use case example of a managed Service Application is the SharePoint User Profile Application. It provides the “User Profile” framework with My Site and My NewsFeed integration across your SharePoint web applications, even across multiple SharePoint farms. </p>
<p>There are multiple sample applications and blogs about this (just use the google!) but I found them a bit tough to follow, and not very repeatable. After shipping 2 enterprise class Service Applications at NewsGator, I decided it’s time to break it down into it’s simplest repeatable pattern. So in the following posts, we’ll talk about:</p>
<ol>
<li>The “Core” of the Service Application: SPIisWebServiceApplication
<li>Service Application Plumbing: Service instances, service provisioning, proxies, and more.
<li>Service Application Plumbing: WCF, the Hard Way
<li>Deploying the Service Application in a WSP. </li>
</ol>
<p><u><strong>SharePoint Projects (WSP projects) are ONLY for Deployment</strong></u></p>
<p>To start off, it’s important to get a good, clean code story. Whenever I write solutions for SharePoint, I follow the golden development rule: “WSPs are ONLY for Deployment”. Keep your code in a class library. Following that rule will make your code much cleaner, simpler to follow, and reusable. For example, at NewsGator we have a WSP deployment project, a data contract project, a service library project (for the Service Application), a Web Part project, and code libraries. I recommend splitting up your code into a similar structure, it makes references a whole lot easier and separates out boundaries. But at a minimum, you’ll need a WSP project for deployment, and a class library. </p>
<p><strong><u>Credit</u></strong></p>
<p>The first pass of my service applications came from Andrew Connell’s sample code. You may find some remnants of that in the code I post, however it’s mostly rewritten from scratch. Big thanks to AC for writing the first reliable sample service application. </p>
<p><u><strong>Let’s Go!</strong></u></p>
<p>To get started, create a SharePoint project named SuperCoolServiceApplication, and a class library named SuperCool.ServiceLibrary. Then follow along the next few posts and you’ll be up and running with your own service application in no time. First we’ll cover the basics. Then we’ll go back and add a database, jobs, and security. </p>
<p>In the class library, make sure you add references to Microsoft.SharePoint and System.ServiceModel. Then get ready, we’ll dive into writing code in the next post. </p>
<p><a href="https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-part-1/">Continue on to part 1!</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/12/14/step-by-step-sharepoint-service-applications-intro/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">268</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint Service Based Ajax: talk from SharePoint Fest Denver</title>
		<link>https://daniellarson.wordpress.com/2010/09/24/sharepoint-service-based-ajax-talk-from-sharepoint-fest-denver/</link>
					<comments>https://daniellarson.wordpress.com/2010/09/24/sharepoint-service-based-ajax-talk-from-sharepoint-fest-denver/#respond</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Fri, 24 Sep 2010 21:32:57 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/09/24/sharepoint-service-based-ajax-talk-from-sharepoint-fest-denver</guid>

					<description><![CDATA[Yesterday I spoke at SharePoint Fest Denver about building service-based AJAX applications on SharePoint Server 2010. Basically, use WCF REST Web Services for data access, and use a JavaScript client to render your Web Parts. We also talked about the &#8230; <a href="https://daniellarson.wordpress.com/2010/09/24/sharepoint-service-based-ajax-talk-from-sharepoint-fest-denver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<div id="msgcns!D3543C5837291E93!12236" class="bvMsg">
<p>Yesterday I spoke at SharePoint Fest Denver about building service-based AJAX applications on SharePoint Server 2010. Basically, use WCF REST Web Services for data access, and use a JavaScript client to render your Web Parts. We also talked about the SharePoint AJAX Library, a simple toolkit for client-side rendering within Web Parts. Not only is this an open source project, it’s at the heart of <a href="http://www.newsgator.com/">NewsGator</a> product code, and has been tested thoroughly and deployed in the top SharePoint installations worldwide through the NewsGator channel.  </p>
<p>Here’s the slide deck plus sample code. The project site for the SharePoint Ajax project is at <a href="http://sharepointajax.codeplex.com/">sharepointajax.codeplex.com</a>. </p>
<li><a href="http://cid-d3543c5837291e93.office.live.com/view.aspx/Public/SharePoint Fest^_DanLarson.pptx">Slide Deck</a></li>
<li><a href="http://cid-d3543c5837291e93.office.live.com/self.aspx/Public/SharePoint.Ajax.Library 1.1 plus Sample Code 9^_2010.zip">Sample code</a> (Includes SharePoint Ajax Library 1.1 for SharePoint 2010, plus sample code)</li>
<p>More posts soon, I’ve been so busy with my children lately and haven’t had time to write! Check out my cute kids on slide 2. <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> </p>
</p></div>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/09/24/sharepoint-service-based-ajax-talk-from-sharepoint-fest-denver/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>SharePoint Snowboarding with NewsGator</title>
		<link>https://daniellarson.wordpress.com/2010/04/09/sharepoint-snowboarding-with-newsgator/</link>
					<comments>https://daniellarson.wordpress.com/2010/04/09/sharepoint-snowboarding-with-newsgator/#respond</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Fri, 09 Apr 2010 17:10:30 +0000</pubDate>
				<category><![CDATA[NewsGator]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/04/09/sharepoint-snowboarding-with-newsgator</guid>

					<description><![CDATA[Where else but Denver can you write SharePoint code all day, and ride fresh powder all afternoon until 8 at night? Joining the usual NewsGator snowboarding crew is Shannon Bray of Planet Technologies. Video shot at Loveland Pass on April &#8230; <a href="https://daniellarson.wordpress.com/2010/04/09/sharepoint-snowboarding-with-newsgator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<div id="msgcns!D3543C5837291E93!9425" class="bvMsg">
<p><a href="https://daniellarson.wordpress.com/wp-content/uploads/2010/04/7145609b23af1093e4ed550bb5b2a7e3.jpg" rel="WLPP"><img border="0" src="https://daniellarson.wordpress.com/wp-content/uploads/2010/04/7145609b23af1093e4ed550bb5b2a7e3.jpg?w=300" /></a> </p>
<p>Where else but Denver can you write SharePoint code all day, and ride fresh powder all afternoon until 8 at night? Joining the usual <a href="http://www.newsgator.com/">NewsGator</a> snowboarding crew is Shannon Bray of Planet Technologies. Video shot at Loveland Pass on April 8, 2010. This might be the last NG run for this year, we’ll pick up the tradition in 2011 from Daylight Savings until April. Next up: we’re shipping betas of NewsGator Social Sites 2010, which will RTM by SP2010 RTM. SharePoint social is not complete without it. </p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;">
<div><iframe class="youtube-player" width="640" height="360" src="https://www.youtube.com/embed/4E26YtzxHVQ?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/04/09/sharepoint-snowboarding-with-newsgator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>

		<media:content url="https://daniellarson.wordpress.com/wp-content/uploads/2010/04/7145609b23af1093e4ed550bb5b2a7e3.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>Chat with the SharePoint MVP Experts</title>
		<link>https://daniellarson.wordpress.com/2010/03/11/chat-with-the-sharepoint-mvp-experts/</link>
					<comments>https://daniellarson.wordpress.com/2010/03/11/chat-with-the-sharepoint-mvp-experts/#respond</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Fri, 12 Mar 2010 00:00:36 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/03/11/chat-with-the-sharepoint-mvp-experts</guid>

					<description><![CDATA[Monday, March 15th at 10MST I’ll be a part of the following MSDN chat on SharePoint 2010. This is a great opportunity to talk to some really smart SharePoint thought leaders about SharePoint 2010. Do you have tough technical questions &#8230; <a href="https://daniellarson.wordpress.com/2010/03/11/chat-with-the-sharepoint-mvp-experts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<div id="msgcns!D3543C5837291E93!8728" class="bvMsg">
<p>Monday, March 15th at 10MST I’ll be a part of the following MSDN chat on SharePoint 2010. This is a great opportunity to talk to some really smart SharePoint thought leaders about SharePoint 2010.  </p>
<p>Do you have tough technical questions regarding SharePoint for which you&#8217;re seeking answers? Do you want to tap into the deep knowledge of the talented Microsoft Most Valuable Professionals? The SharePoint MVPs are the same people you see in the technical community as authors, speakers, user group leaders and answerers in the MSDN forums. This is the first time we have brought these experts together as a collective group to answer your questions live. So please join us and bring on the questions! This chat will cover WSS, MOSS and the SharePoint 2010 beta. Topics include setup and administration, design, development and general questions. </p>
<p>Andrew Connell, Becky Bertram, Brendon Schwartz, Dan Attis, Darrin Bishop, John Ross, Matthew McDermott, Mike Oryszak, Paul Galvin, Paul Schaeflein, Randy Drisgill, and Rob Foster and myself will be leading this chat.  </p>
<p>When:  March 15, 2010<br />Time:  9:00 am PDT<br />Where:  <a href="http://msdn.microsoft.com/en-us/chats/default.aspx">MSDN Chat Room</a><br /><a href="http://www.microsoft.com/communities/chats/vcs/10_0315_msdn_SharePoint.ics">Add</a> this to your calendar<br />Join this Facebook <a href="http://www.facebook.com/?sk=events#!/event.php?eid=336965717244">Event</a><br />Twitter Hash Tag #SPMVPChat</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/03/11/chat-with-the-sharepoint-mvp-experts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET at Arapahoe Community College</title>
		<link>https://daniellarson.wordpress.com/2010/01/20/asp-net-at-arapahoe-community-college/</link>
					<comments>https://daniellarson.wordpress.com/2010/01/20/asp-net-at-arapahoe-community-college/#respond</comments>
		
		<dc:creator><![CDATA[daniellarson]]></dc:creator>
		<pubDate>Thu, 21 Jan 2010 05:48:19 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://daniellarson.wordpress.com/2010/01/20/asp-net-at-arapahoe-community-college</guid>

					<description><![CDATA[We all have something we’d like to do “when we retire”. For me, it’s teaching. After a successful programming career, I’d like to retire and teach at a community college. What better way to give back to the local community &#8230; <a href="https://daniellarson.wordpress.com/2010/01/20/asp-net-at-arapahoe-community-college/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<div id="msgcns!D3543C5837291E93!7588" class="bvMsg">
<p>We all have something we’d like to do “when we retire”. For me, it’s teaching. After a successful programming career, I’d like to retire and teach at a community college. What better way to give back to the local community by teaching others how to excel in their fields? But if there’s something that’s worth doing later in life, why isn’t it worth doing now? </p>
<p>Well, I’m not about to retire YET, and my career at <a href="http://www.newsgator.com/">NewsGator</a> is heating up after the acquisition of <a href="http://www.tomoye.com/">Tomoye</a> this week. But still, why should I wait until I retire? Starting Monday, January 25th I’ll be teaching ASP.NET Application Development at <a href="http://www.arapahoe.edu/">Arapahoe Community College</a>. I’ll cover the basics but we’re going to heat it up pretty quickly as we get into modern web application development. One thing for sure—”classic” ASP.NET is dead. So we’ll cover the underlying technology, course requirements, and then how to build a modern application framework using AJAX and web services. Oh, and a little bit of ASP.NET of course. <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> </p>
<p>If you’re in the Denver area, you can register at <a title="http://www.arapahoe.edu/" href="http://www.arapahoe.edu/">http://www.arapahoe.edu/</a> and sign up for class “CSC 253 MS ASP.NET WEB APP DEVELOPMENT”. Here’s the textbook: <a href="http://www.amazon.com/gp/product/047018759X?ie=UTF8&amp;tag=larsontechnol-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=047018759X">Beginning ASP.NET 3.5 In C#</a><img border="0" src="http://www.assoc-amazon.com/e/ir?t=larsontechnol-20&amp;l=as2&amp;o=1&amp;a=047018759X" />. </p>
<p>UPDATE: STUDENTS, the class folder share is here: <a title="ACC_ASPNET" href="http://cid-d3543c5837291e93.skydrive.live.com/browse.aspx/ACC^_ASPNET">ACC_ASPNET</a>. You can download the class slides and course syllabus. </p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://daniellarson.wordpress.com/2010/01/20/asp-net-at-arapahoe-community-college/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">16</post-id>
		<media:content url="https://2.gravatar.com/avatar/57826fdc708e15b02da06a9bf66d2b0d1a78ca79b4497bf6ab9a5cc2716d4536?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daniellarson</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=larsontechnol-20&#038;l=as2&#038;o=1&#038;a=047018759X" medium="image" />
	</item>
	</channel>
</rss>
