<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Experiences with SharePoint</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/shariq/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/shariq/feed.xml</link>
    <description>Shariq&amp;#039;s Blog</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:51:52 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Simulate Timer Job Solution for SharePoint 2013/Online using App Model &amp; CSOM</title>
      <link>https://docs.microsoft.com/archive/blogs/shariq/simulate-timer-job-solution-for-sharepoint-2013online-using-app-model-csom</link>
      <pubDate>Mon, 09 Dec 2013 11:06:42 GMT</pubDate>
      <dc:creator><![CDATA[Shariq-MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/shariq/2013/12/09/simulate-timer-job-solution-for-sharepoint-2013online-using-app-model-csom/</guid>
      <description><![CDATA[&#160;    PLEASE NOTE: THIS IS STRICTLY A CONCEPT THAT I HAVE UTILIZED AND MAY/MAY NOT CONFIRM TO...]]></description>
      <content:encoded><![CDATA[<blockquote>   <p align="left">&#160;</p>  </blockquote>  <p><strong><font color="#ff0000">PLEASE NOTE: THIS IS STRICTLY A CONCEPT THAT I HAVE UTILIZED AND MAY/MAY NOT CONFIRM TO OFFICIAL MICROSOFT PRODUCT GROUP STATEMENT</font></strong></p>  <p><font size="2">With SharePoint 2013, the emphasis is on loosely coupled architecture that utilizes CSOM/REST. Going forward, it is recommended that custom Solutions like Web Parts be built as Apps or App parts, Event Receivers be Remote Event receivers etc. App scoped External Content Type for BCS is possible as well, and same goes for Workflows. In fact the Workflow framework utilizes Workflow Manager 1.0 that runs outside the SharePoint process.</font></p>  <p><font size="2">So, the benefits are two-fold: </font></p>  <blockquote>   <p><font size="2">1) Secure SharePoint Farm from us ‘Developers’ writing against w3wp.exe :)</font></p>  </blockquote>  <blockquote>   <p><font size="2">2) Ensure our solutions work seamlessly in SharePoint Online as well.</font></p>  </blockquote>  <p><font size="2">All good; but what happens to <strong>Custom Timer Job</strong> that we all have been writing in the past. Though I can still write it using Server Side Object Model (SSOM) for On Premises, it doesn’t really confirm to the recommendation and what happens with SharePoint Online (SP-O)? No SSOM possible :(</font></p>  <p><font size="2">Well, here is what I did to create a Custom Timer Job Simulator service that’s uses App Model &amp; CSOM. Now, this service doesn’t inherits SPJobDefinition but instead this Windows Service runs based on a schedule and utilizes CSOM to perform what is required. </font></p>  <p><font size="2">It’s a two step process.</font></p>  <ul>   <li><font size="2">Create a Provider Hosted App that uses App Only policy for SharePoint 2013/Online</font></li>    <li><font size="2">Create a Windows service that utilizes the code created above</font></li>  </ul>  <h5>Step 1. Create a Provider Hosted App that uses App Only policy</h5>  <p><a title="Steve Peschka" href="https://blogs.technet.com/60796/ProfileUrlRedirect.ashx"><font size="2">Steve Peschka</font></a><font size="2"> has this nice blog post that highlights the use of Apps with App Only policy at <a href="https://blogs.technet.com/b/speschka/archive/2013/07/31/security-in-sharepoint-apps-part-6.aspx">Security in SharePoint Apps - Part 6</a></font><font size="2"></font><font size="2">. Also, </font><a title="Kirk Evans[MSFT]" href="https://blogs.msdn.com/2531/ProfileUrlRedirect.ashx"><font size="2">Kirk Evans[MSFT]</font></a><font size="2"> has a fantastic post on the subject at </font><a href="https://blogs.msdn.com/b/kaevans/archive/2013/02/23/sharepoint-2013-app-only-policy-made-easy.aspx"><font size="2">SharePoint 2013 App Only Policy Made Easy</font></a><font size="2">.</font></p>  <p><font size="2">This gives us a head start onto creating Provider Hosted Apps that utilizes ‘AppOnly; policy. If you are working with On Premise then you have the flexibility to use either </font><a href="https://blogs.msdn.com/b/shariq/archive/2013/05/07/how-to-set-up-high-trust-apps-for-sharepoint-2013-amp-troubleshooting-tips.aspx"><font size="2">High Trust</font></a><font size="2"> or Low Trust Apps. But in SP-O you can only use Low Trust. Setting up a low trust App for SP-O is simple with no additional configuration as o365 has an ACS. But for On-Premise please visit </font><a href="https://msdn.microsoft.com/en-us/library/dn155905.aspx"><font size="2">here</font></a><font size="2"> to set it up.</font></p>  <blockquote>   <p><font size="2">1. For simplicity let’s just use Low Trust App since it works with On-Premise &amp; SP-O. So go ahead and create a SharePoint Provider Hosted App using Visual Studio 2012 (don’t change the default option of using ACS).</font></p>  </blockquote>  <blockquote>   <p><font size="2">Below is the snapshot of the code used inside my Low Trust App. It creates an ‘AppOnlyAccessToken’ that’s used to create the ‘ClientContext’ which eventually updates a custom List. This could very well do any other task as well (things which are possible with the powerful CSOM). Verify that the App works fine with both On Premise &amp; Online. Full sample code solution is attached below.</font></p>  </blockquote>  <blockquote>   <p>&#160;&#160; <font size="2"><em>protected void Page_Load(object sender, EventArgs e)          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //constant string SharePoint principal           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string SharePointPrincipal = &quot;00000003-0000-0ff1-ce00-000000000000&quot;;</em></font></p>  </blockquote>  <font size="2"><em></em></font>  <blockquote>   <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uri hostWeb = new Uri(Page.Request[&quot;SPHostUrl&quot;]);</em></font></p>  </blockquote>  <font size="2"><em></em></font>  <blockquote>   <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string realm = TokenHelper.GetRealmFromTargetUrl(hostWeb);</em></font></p>  </blockquote>  <font size="2"><em></em></font>  <blockquote>   <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string appOnlyAccessToken = TokenHelper.GetAppOnlyAccessToken(SharePointPrincipal, hostWeb.Authority, realm).AccessToken;</em></font></p>  </blockquote>  <font size="2"><em></em></font>  <blockquote>   <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(hostWeb.ToString(), appOnlyAccessToken))          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (clientContext != null)           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //ShariqTest is a custom List in my SharePoint site -both Om Prem &amp; Online           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var myList = clientContext.Web.Lists.GetByTitle(&quot;ShariqTest&quot;);           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ListItemCreationInformation listItemCreate = new ListItemCreationInformation();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft.SharePoint.Client.ListItem newItem = myList.AddItem(listItemCreate);           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; newItem[&quot;Title&quot;] = &quot;Testing &quot; ;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; newItem.Update();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; clientContext.ExecuteQuery();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></font></p>  </blockquote>  <blockquote>   <p><font size="2">2.&#160; If you are looking at using only the High Trust App, then the process pretty much remains same. The code to get ‘AppOnlyAccessToken’ is a bit different. Please follow <a href="https://blogs.technet.com/b/speschka/archive/2013/07/31/security-in-sharepoint-apps-part-6.aspx">this</a> and the attached sample that <a title="Steve Peschka" href="https://blogs.technet.com/60796/ProfileUrlRedirect.ashx"><font size="2">Steve Peschka</font></a><font size="2"> shared.</font></font></p>    <p><font size="2">3. Please provide appropriate <a href="https://msdn.microsoft.com/en-us/library/office/fp142383.aspx">App permissions</a>.&#160;&#160; </font></p>    <p><font size="2">4. Now, once you are happy with the App functionality (mine just adds an item in a list). Verify the ‘<strong>App Identifier</strong>’ with the ‘<strong>App Display Name</strong>’ at <strong>Site Settings -&gt; Site app permissions</strong> . Please note that another ‘F5’ Hit from VS 2012 would generate a new ‘App Identifier’ as VS will generate a new ‘<strong>ClientId</strong>’.</font></p>  </blockquote>  <h5>Step 2. Create a Windows Service that is scheduled to run [it utilizes the above code]</h5>  <p><font size="2">Check this </font><a href="https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx"><font size="2">How to: Create Windows Services</font></a><font size="2">, if you want to understand the details around creating a windows service that runs based on a schedule. Though I will mention it for everyone’s interest. </font></p>  <blockquote>   <p><font size="2">1. Create a Windows Service by selecting <strong>Windows Service</strong> in the list of Visual C# project templates. I named it ‘SPTimerJobSimulation’.</font></p>  </blockquote>  <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8750.image_6B47CD3C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8750.image_5F00_6B47CD3C.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4331.image_thumb_4137A947.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4331.image_5F00_thumb_5F00_4137A947.png" width="500" height="277" /></a></p>  <p>&#160;</p>  <font size="2"></font>  <blockquote>   <p><font size="2">2. Add ‘<strong>TokenHelper.cs</strong>’ class from the App project created above (Step 1). Then remove the namespace declaration from this class along with additional braces ‘{}’ from the code.</font></p>    <p><font size="2"></font></p>    <p><font size="2">3. Add the additional <strong>references</strong> (ref below). As this service needs to work with CSOM and other references needed for ‘TokenHelper.cs‘ class.</font></p>  </blockquote>  <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5810.image_7039E51E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5810.image_5F00_7039E51E.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4213.image_thumb_6CD84D76.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4213.image_5F00_thumb_5F00_6CD84D76.png" width="237" height="257" /></a></p>  <p>&#160;</p>  <blockquote>   <p><font size="2">4. Open ‘<strong>Service1.cs</strong>’ and switch to code view. I have pasted almost the entire code below. Essentially, I have moved the code from Default.aspx.cs. Just make sure to comment out the hard coded Uri to point to the relevant On Premise or SP-O site.</font></p>  </blockquote>  <blockquote>   <p><font size="2"><em>public partial class Service1 : ServiceBase         <br />&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static string SharePointPrincipal = &quot;00000003-0000-0ff1-ce00-000000000000&quot;;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; static Timer SPtimer;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public Service1()           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitializeComponent();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override void OnStart(string[] args)          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPtimer = new Timer();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //schedule an interval of 2 minutes           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPtimer.Interval = 1000 * 60 * 2;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPtimer.Elapsed += SPtimer_Elapsed;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; startSPtimer();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; void SPtimer_Elapsed(object sender, ElapsedEventArgs e)          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Comment out either of the below based on On Premise server or Online           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uri hostWeb = new Uri(&quot;</em></font><a href="https://tenant/sites/DevCenter&quot;);"><font size="2"><em>https://tenant/sites/DevCenter&quot;);</em></font></a></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //Below line works with On line          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uri hostWeb = new Uri(&quot;</em></font><a href="https://tenant.sharepoint.com/sites/Develop&quot;);"><font size="2"><em>https://tenant.sharepoint.com/sites/Develop&quot;);</em></font></a></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string realm = TokenHelper.GetRealmFromTargetUrl(hostWeb);</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string appOnlyAccessToken = TokenHelper.GetAppOnlyAccessToken(SharePointPrincipal, hostWeb.Authority, realm).AccessToken;</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(hostWeb.ToString(), appOnlyAccessToken))          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (clientContext != null)           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var myList = clientContext.Web.Lists.GetByTitle(&quot;ShariqTest&quot;);           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ListItemCreationInformation listItemCreate = new ListItemCreationInformation();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft.SharePoint.Client.ListItem newItem = myList.AddItem(listItemCreate);           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; newItem[&quot;Title&quot;] = &quot;Added from Timer Job&quot;;           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; newItem.Update();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; clientContext.ExecuteQuery();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void startSPtimer()          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPtimer.Start();           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></font></p>   <font size="2"><em></em></font>    <p><font size="2"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected override void OnStop()          <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {           <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }           <br />&#160;&#160;&#160; }</em></font></p>    <p><em><font size="2"></font></em></p>  </blockquote>  <blockquote>   <p><font size="2">5. Next up, we need to add the Application settings (ref below). So go to Project settings and Select ‘<strong>Settings</strong>’ to add the relevant &lt;appSettings&gt; from the Web.Config of your App project. Add ‘<strong>ClientId</strong>’ &amp; ‘<strong>ClientSecret</strong>’ with relevant values (point ‘3’, under Step 1 above). Also change scope to ‘Application’. </font></p>    <p><font size="2"></font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1362.image_111D31F9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1362.image_5F00_111D31F9.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4454.image_thumb_0774C3C3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4454.image_5F00_thumb_5F00_0774C3C3.png" width="599" height="138" /></a></p>    <p><font color="#ff0000">Edit: <font color="#000000">Also you need to open your TokenHelper.cs file and comment out</font> <strong>private static readonly string ClientId </strong><font color="#000000">and replace it with</font> yourAppsNamespace.Properties.Settings.Default.ClientId. <font color="#000000">Same goes for</font> <strong>private static readonly string ClientSecret,</strong><font color="#000000"> replace it with</font> yourAppsNamespace.Properties.Settings.Default.IssuerId.</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7230.image_2BA2824A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7230.image_5F00_2BA2824A.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2335.image_thumb_463EF896.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2335.image_5F00_thumb_5F00_463EF896.png" width="725" height="133" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">6. We are almost done. Now we need to Debug and Install this windows service, let’s create the installers by opening <strong>Service1.cs </strong>file<strong> </strong>and with the designer in focus, right-click, Add Installer (ref below).</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8228.image_5E1D7BC4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8228.image_5F00_5E1D7BC4.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8507.image_thumb_110D0C2C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8507.image_5F00_thumb_5F00_110D0C2C.png" width="330" height="168" /></a></p>    <p>&#160;</p>  </blockquote>  <blockquote>   <p><font size="2">7.&#160; To install a Windows service. Open <strong>Developer Command Prompt</strong> as Administrator. Navigate to the folder that contains your project's output. Install the service using the ‘installutil.exe’ command (ref below).</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1033.image_4EB9F3E8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1033.image_5F00_4EB9F3E8.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1488.image_thumb_05B3D222.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1488.image_5F00_thumb_5F00_05B3D222.png" width="464" height="121" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">8.&#160; It will prompt you for Service Login credentials. Provide appropriately.</font>&#160;</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0842.image_519F32CE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0842.image_5F00_519F32CE.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7651.image_thumb_3AFCE487.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7651.image_5F00_thumb_5F00_3AFCE487.png" width="310" height="144" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">9.&#160; The Service would be installed (ref below).</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0045.image_06E84534.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0045.image_5F00_06E84534.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8865.image_thumb_0A39B70F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8865.image_5F00_thumb_5F00_0A39B70F.png" width="655" height="424" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">10. Open ‘<strong>Services</strong>’ and you should see your service listed. Go ahead and <strong>Start</strong> our service (ref below).</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5466.image_1725D539.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5466.image_5F00_1725D539.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7331.image_thumb_199EE12A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7331.image_5F00_thumb_5F00_199EE12A.png" width="644" height="66" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">11.&#160; Now let’s go and debug the service. Go to Debug –&gt;Attach to Process and attach relevant process.</font></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4162.image_30117FB1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4162.image_5F00_30117FB1.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8512.image_thumb_2911CD2C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8512.image_5F00_thumb_5F00_2911CD2C.png" width="644" height="476" /></a></p>  </blockquote>  <blockquote>   <p><font size="2">12.&#160; Now you should be able to debug your service. It should hit the breakpoint based on the schedule that you coded under OnStart method.</font></p>  </blockquote>  <p><font size="2">Now this Scheduled Service adds an item every 2 minutes to my SharePoint site :). But it could do anything (possible with CSOM) on either SharePoint On-Premise or Online based on your requirement. There might be an additional request around hosting this Service in <strong>Azure</strong> specially while you are working with SP-O. So a nice pattern could be:</font></p>  <ul>   <li>Host the workload processing logic inside a regular Azure worker role.</li>    <li>Use Windows Azure Scheduler to queue work items in recurring scheduled fashion.</li>    <li>Have the Azure worker role pick-up work items from queue and execute the workload. After the work is finished, delete the item from queue.</li>  </ul>  <p><font size="2">A couple of scenario which made me write a SharePoint timer job in the 2010 world was:</font></p>  <ul>   <li><font size="2">Sending a reminder email based on a particular list value. This was used with a workflow. </font></li>    <li><font size="2">Updating SharePoint List data to have fresh data based on an external database change. </font></li>  </ul>  <p><font size="2">So, both these scenarios can be easily implemented with my Custom Timer Job simulator that doesn’t use SSOM. </font></p>  <p><font size="2">You can <strong>download the complete sample</strong> from</font> <a href="https://sdrv.ms/1bmGQh0">here</a><font size="2">.</font></p>  <p><font size="2">This is super powerful and I enjoyed it. <font size="2">Hope you like this too!</font>&#160;</font></p>  <p><font size="2">Your comments/suggestions are welcome, as always!</font></p>  <p><font size="2">Cheers !</font></p>  <p><font size="2">Shariq</font></p>]]></content:encoded>
    </item>
    <item>
      <title>How to - Set up High Trust Apps for SharePoint 2013 &amp; Troubleshooting Tips</title>
      <link>https://docs.microsoft.com/archive/blogs/shariq/how-to-set-up-high-trust-apps-for-sharepoint-2013-troubleshooting-tips</link>
      <pubDate>Tue, 07 May 2013 12:53:02 GMT</pubDate>
      <dc:creator><![CDATA[Shariq-MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/shariq/2013/05/07/how-to-set-up-high-trust-apps-for-sharepoint-2013-troubleshooting-tips/</guid>
      <description><![CDATA[SharePointers, I am back !!  This time with my experiences with the ever engrossing SharePoint 2013....]]></description>
      <content:encoded><![CDATA[<p>SharePointers, I am back !!</p>  <p>This time with my experiences with the ever engrossing SharePoint 2013. Last week I was setting up High Trust Apps that uses the server-to-server (S2S) protocol. This is a Provider Hosted App deployed in a private network which eliminates the need to involve ACS for creating Authentication tokens. In essence an S2S trust represents a trusted connection between a client app running on a local app server and the web servers in the SharePoint farm. </p>  <p>We need to set up the S2S Security token issuer service (STS) to provide access tokens for authentication. The S2S STS creates temporary access tokens signed with your own certificate. </p>  <p>So, lets go ahead and see the steps needed to set up your High Trust Apps. But at the outset, please ensure that you have the below mentioned steps in place to avoid any issues. </p>  <h5>Prerequisite Step:</h5>  <ol>   <li><strong>App Isolation set up :</strong> utilize either <a href="https://technet.microsoft.com/en-us/library/fp161236.aspx">Configure an environment for apps for SharePoint</a> or <a href="https://blogs.msdn.com/b/tomvan/archive/2012/11/20/prepare-sharepoint-2013-server-for-app-development-create-an-isolated-app-domain-powershell-script.aspx">Setting up your App domain for SharePoint 2013 via PowerShell</a> to set it up.</li>    <li><strong>Use non Farm Account (SHAREPOINT\SYSTEM) : </strong> instead use a separate Developer Account that will used for App development. Ensure this user has right set of privileges (part of local administrators group on the Developer box, right permissions set on the relevant databases etc.).</li>    <li><strong>User Profile Service Application set up :&#160; </strong>shouldn’t be difficult for most folks; anyways you can refer to <a href="https://social.technet.microsoft.com/wiki/contents/articles/12518.sharepoint-2013-user-profile-service-application.aspx">SharePoint 2013 - User Profile Service Application</a> &amp; <a href="https://technet.microsoft.com/en-us/library/ee721052.aspx">Create, edit, or delete User Profile service applications in SharePoint Server 2013</a> for additional info.</li> </ol>  <h5>Step 1: Create a Certificate</h5>  <blockquote>   <p>1. In the development environment you can use a self-signed certificate, but you would need a commercial certificate when you publish your Apps to store. So we will create a self signed one. In the IIS manager, click on <strong>Server Certificates</strong>.<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0602.image_4D3B3380.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0602.image_5F00_4D3B3380.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2425.image_thumb_63419F12.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2425.image_5F00_thumb_5F00_63419F12.png" width="644" height="337" /></a></p> </blockquote>  <blockquote>   <p>2. Click on <b>Create Self Signed Certificate</b></p> </blockquote>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1351.image_3A2B60A9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1351.image_5F00_3A2B60A9.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/3414.image_thumb_23F54557.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/3414.image_5F00_thumb_5F00_23F54557.png" width="163" height="160" /></a></p> </blockquote>  <blockquote>   <p>3. Enter some meaningful name like <strong>HighTrustCert </strong>and Click on <strong>Ok. </strong></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7608.image_692D9C80.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7608.image_5F00_692D9C80.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4162.image_thumb_27B2EA27.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4162.image_5F00_thumb_5F00_27B2EA27.png" width="497" height="370" /></a></p> </blockquote>  <blockquote>   <p>4. Now we need to export the <strong>personal exchange format (.pfx) </strong>file. Right Click on the Certificate in IIS click on <strong>Export </strong>and provide an accessible location. Also enter the password that you want to use and Click on <strong>Ok</strong>&#160; </p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2133.image_56A9DF43.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2133.image_5F00_56A9DF43.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4572.image_thumb_4E4609EC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4572.image_5F00_thumb_5F00_4E4609EC.png" width="313" height="247" /></a>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0844.image_2C7A315B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0844.image_5F00_2C7A315B.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8867.image_thumb_721EBB79.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8867.image_5F00_thumb_5F00_721EBB79.png" width="306" height="244" /></a></p>    <p>5. Next, double click on the Certificate in IIS. Click on <strong>Details </strong>tab and click on <strong>Copy to File.</strong></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0172.image_64E22064.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0172.image_5F00_64E22064.png"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4786.image_6692EC38.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4786.image_5F00_6692EC38.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1172.image_thumb_361279C4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1172.image_5F00_thumb_5F00_361279C4.png" width="388" height="484" /></a></a></p>    <p>6. Now you should see the <strong>Certificate Export Wizard</strong> (remember earlier we exported the .pfx file). The first screen elucidate the significance of what we are doing. Keep Clicking <strong>Next </strong>across the three screens. Below screenshots demonstrate the same. I keep all the default options. Just one thing to mark that now we are now exporting the <strong>.cer </strong>file. I choose the same location. Click on <strong>Save.</strong></p>    <p>&#160;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5811.image_056F641A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5811.image_5F00_056F641A.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4810.image_thumb_43F4B1C0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4810.image_5F00_thumb_5F00_43F4B1C0.png" width="244" height="236" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/3833.image_6D887CF3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/3833.image_5F00_6D887CF3.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4403.image_thumb_40FF4D0D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4403.image_5F00_thumb_5F00_40FF4D0D.png" width="244" height="236" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/3312.image_6A931840.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/3312.image_5F00_6A931840.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5140.image_thumb_5705B89F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5140.image_5F00_thumb_5F00_5705B89F.png" width="244" height="232" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0116.image_4F896943.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0116.image_5F00_4F896943.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2654.image_thumb_38E71AFC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2654.image_5F00_thumb_5F00_38E71AFC.png" width="644" height="382" /></a></p>    <p>and finally, click on <strong>Finish. </strong>You should see you the message “<strong>The export was successful</strong>”.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/3225.image_7DB33F30.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/3225.image_5F00_7DB33F30.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1050.image_thumb_3C388CD7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1050.image_5F00_thumb_5F00_3C388CD7.png" width="528" height="484" /></a></p>    <p>7. To verify, go to your <strong>Trusted Root Certification Authorities Store</strong>&#160; and you should see your Certificate there. If you can’t locate it, follow the <strong>first 7 steps (only)</strong> described at <a href="https://technet.microsoft.com/en-us/library/#BKMK_addlocal">Adding certificates to the Trusted Root Certification Authorities store for a local computer</a>. Remember we just need to confirm our certificate is available or not. <em><strong>If you are here, the battle is half won</strong></em>.</p> </blockquote>  <h5>Step 2 : Run Windows PowerShell cmdlets to set up trusted security token service</h5>  <blockquote>   <p>1. Run SharePoint 2013 Management Shell as administrator. First thing first, you need an Issuer ID. Use the below PowerShell cmdlets to get one. Remember to make note of this, as we will use it later. An important point, it has to be <strong>Lowercase</strong> only.</p>    <p>[System.Guid]::NewGuid()</p>    <p>2. Run the below PowerShell cmdlets to <strong>create trusted security token service</strong>. </p>    <p>$issuerID = &quot;29b0ebdd-791b-41c3-b1f7-a4152a1b7a8d&quot;      <br />$publicCertPath = &quot;C:\HighTrustCert.cer&quot;      <br />$certificate = Get-PfxCertificate $publicCertPath      <br />$web = Get-SPWeb &quot;https://sp/sites/DevCenter&quot;      <br />$realm = Get-SPAuthenticationRealm -ServiceContext $web.Site      <br />$fullAppIdentifier = $issuerId + '@' + $realm      <br />New-SPTrustedSecurityTokenIssuer -Name &quot;High Trust App&quot; -Certificate $certificate -RegisteredIssuerName $fullAppIdentifier -IsTrustBroker      <br />iisreset      <br /></p>    <p><strong>Significance/additional info of the cmdlets</strong> </p>    <ol>     <li><strong>issuerID</strong> : assigning the GUID generated in the previous step</li>      <li><strong>publicCertPath</strong> : path where I saved my .cer file.</li>      <li><strong>web</strong> : your Developer site URL</li>      <li><strong>realm</strong> : should be the same as your farm ID</li>      <li><strong>New-SPTrustedSecurityTokenIssuer</strong> : Just a tip, when you use the Name parameter it can be helpful to include a readable name, such as “High Trust App” or “Contoso S2S apps” instead of the issuer ID.</li>      <li><strong>-IsTrustBroker: </strong>this flag ensures that you can use the same certificate for other apps as well. If you don’t include this, you might receive “The issuer of the token is not a trusted issuer&quot; error. So we have two possible approaches each having their own pros and cons .i.e.<em> use the same certificate shared by multiple apps</em> <strong>Or </strong><em>use a separate certificate for each app.</em> Read additional details at <a href="https://msdn.microsoft.com/en-us/library/jj945118.aspx">Guidelines for using certificates in high-trust apps for SharePoint 2013</a></li>      <li><strong>iisreset</strong> : to ensure the Issuer becomes valid, else it takes 24 hours. </li>   </ol>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>    <p>3. Additionally you can turn off the <strong>https requirements</strong> using below PowerShell cmdlets. But ensure to turn it <strong>on</strong> by changing $true to $false in the second cmdlet below.</p>    <p>$serviceConfig = Get-SPSecurityTokenServiceConfig     <br />$serviceConfig.AllowOAuthOverHttp = $true      <br />$serviceConfig.Update()</p>    <p>4. Refer to the screenshot below of for the complete steps:</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6661.image_6CA73B1E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6661.image_5F00_6CA73B1E.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6177.image_thumb_069AFB41.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6177.image_5F00_thumb_5F00_069AFB41.png" width="451" height="525" /></a></p>    <p><em><strong>If you are here, you are almost done</strong> </em></p> </blockquote>  <h5>Step 3 : Create a Simple “High Trust” Provider Hosted App using Visual Studio 2012</h5>  <blockquote>   <p>1.&#160; Open Visual Studio 2012, under Office/SharePoint section select <strong>App for SharePoint 2013</strong>. Enter a name and click <strong>OK</strong></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8400.image_283EFA41.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8400.image_5F00_283EFA41.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4452.image_thumb_119CABFA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4452.image_5F00_thumb_5F00_119CABFA.png" width="644" height="427" /></a></p>    <p>2. Select<strong> Provider-hosted</strong> and don’t forget to Click <strong>Next </strong>(and not Finish)</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0647.image_2F9AB9EE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0647.image_5F00_2F9AB9EE.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4341.image_thumb_1C0D5A4D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4341.image_5F00_thumb_5F00_1C0D5A4D.png" width="644" height="469" /></a></p>   </blockquote>  <blockquote>   <p>3. Then select <strong>Use a Certificate </strong>and provide the location of your certificate <strong>.pfx </strong>file. Provide the same password as provided in sub-step 4 under <strong>Step 1.&#160; </strong>The Issuer ID should be same as created above, under sub-step 1 of <strong>Step 2. </strong>Then Click <strong>Finish.</strong></p> </blockquote>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5822.image_32EC2BC9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5822.image_5F00_32EC2BC9.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7484.image_thumb_0662FBE3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7484.image_5F00_thumb_5F00_0662FBE3.png" width="644" height="464" /></a></p> </blockquote>  <blockquote>   <p>4. The App Solution should be set up with its two projects.&#160; Since we don’t intend to do anything extravagant, if you go ahead and Hit F5. After a few seconds you should see the below screen asking whether you ‘Trust’ this App. Click <strong>Trust it.</strong></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0513.image_2F8A9421.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0513.image_5F00_2F8A9421.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/4807.image_thumb_6E0FE1C7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/4807.image_5F00_thumb_5F00_6E0FE1C7.png" width="387" height="178" /></a></p>    <p>5. And we are done!! You should see the title of your Developer site displayed as shown below. Yay <img style="style" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0456.wlEmoticon-smile_6FD8615F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0456.wlEmoticon_2D00_smile_5F00_6FD8615F.png" /></p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6523.image_3A5F9F3A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6523.image_5F00_3A5F9F3A.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7183.image_thumb_5FE91C9B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7183.image_5F00_thumb_5F00_5FE91C9B.png" width="443" height="242" /></a></p>    <p> 6. Note that the App is right now hosted on the <strong>IIS Express</strong>.</p>    <h3>&#160;</h3>    <h3>Important troubleshooting tips &amp; tricks</h3>    <p>Each step above should not take more than 5 minutes each, if there are no issues with your environment. In case you face any issues. then follow the important tips &amp; tricks that I have collated below which I learnt along the way. Big thanks to <a href="https://blogs.msdn.com/2531/ProfileUrlRedirect.ashx">Kirk Evans[MSFT]</a> for helping me with this.</p>    <ol>     <li>Make sure all the Prerequisite Steps listed at the start of the article are in place.</li>      <li>If you run into <strong>401 unauthorized error when running a high-trust app</strong>. Try the steps below: </li>   </ol>    <ul>     <li>Use the PowerShell cmdlet to get the List of all TrustedSecurityTokenIssuer in your Farm</li>   </ul>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Get-SPTrustedSecurityTokenIssuer | select Name,RegisteredIssuerName | fl</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/8357.image_4C5BBCFA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/8357.image_5F00_4C5BBCFA.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1004.image_thumb_11941424.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1004.image_5F00_thumb_5F00_11941424.png" width="556" height="241" /></a></p>    <ul>     <li>This shows the Name, Registered Issuer Name for all registered security token issuers.&#160; I had five of them.</li>      <li>The first one <strong>00000005-0000-0000-c000-000000000000</strong> is for Workflows.</li>      <li>Observe rest of the list, the correct token issuer should be of the format <strong>issuerID@Realm</strong> if you have a registration in there that’s missing the issuerID or Realm portion of the RegisteredIssuerName, you can see the <strong>401</strong> error.&#160; </li>      <li>For us it is <strong>29b0ebdd-791b-41c3-b1f7-a4152a1b7a8d</strong>@<strong>8165b002-8510-4d2d-b0f7-67b0a716a3f6. </strong>The portion before ‘@’ is our ‘issuerID’ and after is the ‘Realm’ (ref to the above screenshot).</li>      <li>The realm should be the same for any issuers that you registered manually, and it should be the same as your <strong>farm ID </strong>(use the below cmdlet to find that):</li>      <p>Get-SPFarm | select Id</p>      <p>And you can verify the Realm using the below cmdlet</p>      <p>$spurl =&quot;https://sp/sites/DevCenter&quot;       <br />$spsite = Get-SPSite $spurl        <br />$realm = Get-SPAuthenticationRealm -ServiceContext $spsite        <br />Write $realm</p>      <li>If you see a token issuers that is not in correct format, that’s the <strong>killer</strong> and you must remove that (but don’t dare to remove the one for the <strong>workflows <img style="style" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0456.wlEmoticon-smile_6FD8615F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0456.wlEmoticon_2D00_smile_5F00_6FD8615F.png" /></strong>). You can use the below PS to remove any SPTrustedSecurityTokenIssuer. Make sure to supply correct RegisteredIssuerName found above.</li>   </ul>    <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Get-SPTrustedSecurityTokenIssuer | ?{$_.RegisteredIssuerName -eq &quot;29b0ebdd-791b-41c3-b1f7-a4152a1b7a8d@8165b002-8510-4d2d-b0f7-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 67b0a716a3f6&quot;} | Remove-SPTrustedSecurityTokenIssuer&#160; </p>    <ul>     <li>You should also double-check that you are using the correct public key portion (the .CER file) for the private key (the .PFX file) that is on your app’s IIS server.&#160; It is always worth verifying this step again.&#160; </li>      <li>Then make sure that the issuerID that’s in the RegisteredIssuerName (before the “@” symbol) matches the value that you have in web.config. Open the web.config file of your App’s web project.</li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2474.image_0B5E780B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2474.image_5F00_0B5E780B.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7651.image_thumb_380731E4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7651.image_5F00_thumb_5F00_380731E4.png" width="713" height="87" /></a>&#160; </p>    <ul>     <li>Also navigate to the ‘<strong>Site App Permissions’</strong> page and you will see all the <strong>App Identifier</strong> listed. Notice that your App Identifier is of the structure <strong>ClientID@Realm</strong>. Verify the <strong>clientId</strong> in the web.config (above step).;</li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6560.image_7A2A9A67.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6560.image_5F00_7A2A9A67.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6165.image_thumb_669D3AC6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6165.image_5F00_thumb_5F00_669D3AC6.png" width="756" height="40" /></a></p>    <ul>     <li>Next, use Get-SPTrustedSecurityTokenIssuer and look at the certificate thumbprint for your issuer and compare it with the thumbprint of the certificate you used in PowerShell. </li>   </ul>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7343.image_49C2656F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7343.image_5F00_49C2656F.png"><img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0572.image_thumb_0847B316.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0572.image_5F00_thumb_5F00_0847B316.png" width="354" height="336" /></a></p>    <p>&#160;&#160;&#160;&#160; 3. I would <strong>recommend</strong> reviewing these blogs as well: </p>    <ul>     <li><a href="https://msdn.microsoft.com/en-us/library/fp179932.aspx">High-trust apps (server-to-server apps) on-premises</a>&#160;</li>      <li><a href="https://blogs.technet.com/b/speschka/archive/2012/11/01/more-troubleshooting-tips-for-high-trust-apps-on-sharepoint-2013.aspx">More Troubleshooting Tips for High Trust Apps on SharePoint 2013</a></li>      <li><a href="https://msdn.microsoft.com/en-us/library/jj945118.aspx">Guidelines for using certificates in high-trust apps for SharePoint 2013</a></li>   </ul> </blockquote>  <blockquote>   <p>&#160;</p>    <p>That was a lot of info, I'm gonna call it a day! </p>    <p>Cheers!</p></blockquote>]]></content:encoded>
    </item>
    <item>
      <title>Integrating SharePoint 2010 and CRM 2011</title>
      <link>https://docs.microsoft.com/archive/blogs/shariq/integrating-sharepoint-2010-and-crm-2011</link>
      <pubDate>Fri, 25 Jan 2013 13:33:30 GMT</pubDate>
      <dc:creator><![CDATA[Shariq-MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/shariq/2013/01/25/integrating-sharepoint-2010-and-crm-2011/</guid>
      <description><![CDATA[Part 3: Publishing CRM entities in SharePoint.  Hello SharePointers !!  I have been working with...]]></description>
      <content:encoded><![CDATA[<h2> </h2>  <h3>Part 3: Publishing CRM entities in SharePoint.</h3>  <p>Hello SharePointers !!</p>  <p>I have been working with SharePoint for many years, but this is the first time I decided to blog about something. </p>  <p>The driving force behind choosing this particular topic is the two-fold: Firstly, there is not enough information available and secondly, due to the constant reminders by colleague <a href="https://blogs.technet.com/181357/ProfileUrlRedirect.ashx">Andy</a> to help the larger community out there. </p>  <p><a href="https://blogs.technet.com/181357/ProfileUrlRedirect.ashx">Andy</a>, himself has published <a href="https://blogs.technet.com/b/anand_nigam/archive/2011/12/04/crm-2011-and-sharepoint-2010-integration-part-1.aspx">multi-part blog series</a> on this topic and in essence this post forms the part 3 of his series.</p>  <p>Over here we will see how we can fetch and display complete set of entity information from CRM 2011 in a SharePoint Web part. That is in the SharePoint Web Part I will have a drop down list with the collection of all CRM ‘<strong>Entity</strong>’ and another drop down that will contain the associated ‘<strong>Views</strong>’ and finally the Entity Result set. But before we do that it’s important to understand why this is not straight forward!</p>  <p><strong>Thought Process:</strong></p>  <p>1) CRM 2011 provides SDK and I can always develop custom solutions. If I choose to refer to “<a href="https://msdn.microsoft.com/en-us/library/gg695790.aspx">Walkthrough: Build a Web Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions</a>” I can easily display CRM 2011 entity information in a Web Application.</p>  <p>2) That means I can easily transform those custom solutions (like a Web Application) into a SharePoint 2010 web part, and bingo! We are all set!</p>  <p><strong>Catch:</strong></p>  <p>1) CRM 2011 is based on .Net framework 4.0 and SP 2010 is on .Net 3.5. So if you try to implement the step 2 you can’t even build your SharePoint Web Part forget about deploying it. </p>  <p><strong>Resolution [Important Steps]:</strong></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2844.image_thumb25_2F24F12A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2844.image_5F00_thumb25_5F00_2F24F12A.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image_thumb25" border="0" alt="image_thumb25" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7624.image_thumb25_thumb_26C11BD3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7624.image_5F00_thumb25_5F00_thumb_5F00_26C11BD3.png" width="508" height="153" /></a></p>  <p>1) Publish an intermediary WCF service with relevant methods to expose information from CRM 2011.</p>  <p>2) Create a SharePoint Web Part and make appropriate calls to the WCF service and then transform the result set as per your needs for the end user.</p>  <h4><strong></strong> </h4>  <h4><strong>The Steps in detail:</strong></h4>  <p><strong>1) We need to create and publish a WCF service to call in CRM 2011. This service can have multiple facets based on your needs; may be you intend to perform add/edit/delete apart from just “display” so create the WCF methods judiciously. For now I will stick to the display part.</strong></p>  <p><strong>IMP</strong>: The code blocks below doesn’t confirm to the coding best practices but does work, and I am sure you guys can transform it accordingly. I have ripped the pieces from from all over the web </p>  <p>a) Generate Early Bound Types:</p>  <p>Run the CrmSvcUtil.exe tool, with the <strong>Microsoft.Xrm.Client.CodeGeneration</strong> extension, to generate your entity classes and service contexts. </p>  <p>The following example command creates a file called “Xrm.cs” that points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command. </p>  <p><font size="2">crmsvcutil.exe /codeCustomization:&quot;Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration&quot;     <br />/out:Xrm\Xrm.cs /url:</font><a href="https://dpm2012/fabrikam/XRMServices/2011/Organization.svc"><font size="2">https://dpm2012/fabrikam/XRMServices/2011/Organization.svc</font></a><font size="2"> /domain:CONTOSO /username:spfarm      <br />/password:Welcome@123 /namespace:Xrm /serviceContextName:XrmServiceContext</font></p>  <pre class="csharpcode"></pre>

<p>b) Use Visual Studio 2010 to create a WCF Service Application (ensure .NET Framework 4).</p>

<p> </p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1447.Img1_thumb3_1E5D467C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1447.Img1_5F00_thumb3_5F00_1E5D467C.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="Img1_thumb3" border="0" alt="Img1_thumb3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6138.Img1_thumb3_thumb_0344776E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6138.Img1_5F00_thumb3_5F00_thumb_5F00_0344776E.png" width="648" height="446" /></a></p>

<div class="csharpcode">
  <pre><font size="1" face="Segoe UI"></font></pre>

  <p><font color="#333333" face="Segoe UI">c) Right-click the project in Visual Studio, click <strong>Add</strong>, and then click <strong>Existing Item</strong>. Select the “xrm.cs” file that </font><font color="#333333" face="Segoe UI">you created when you generated the early bound types.</font></p>
  <font face="Segoe UI"></font>

  <p><font color="#333333" face="Segoe UI">d) Right-click the project in Visual Studio, click <strong>Add, a</strong>dd a new class to the project. The Add New Item dialog </font><font color="#333333" face="Segoe UI">box appears. Rename the class as Entities.cs. Similarly add one more class and name it as Views.cs</font></p>
  <font face="Segoe UI"></font>

  <p><font color="#333333" face="Segoe UI">e) Add couple of properties in <strong>both</strong> these classes (please name it appropriately)</font></p>

  <div class="csharpcode">
    <pre class="alt"><span class="kwrd">public</span> <span class="kwrd">string</span> MyProperty { get; set; }</pre>
  </div>

  <div class="csharpcode"></div>

  <div class="csharpcode">
    <pre><span class="kwrd">public</span> <span class="kwrd">string</span> MyProperty1 { get; set; }</pre>
  </div>

  <div class="csharpcode">
    <pre> </pre>
  </div>

  <div class="csharpcode">
    <p><font face="Segoe UI">f) Add the references as shown below (for the CRM dll the Source will be <code>SDK\bin<font size="2" face="Segoe UI">, don’t search for C:\Shariq <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6644.wlEmoticon-smile_1618FB18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6644.wlEmoticon_2D00_smile_5F00_1618FB18.png" /></font>)</code> </font></p>

    <pre> </pre>

    <pre><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/0743.image_thumb7_67BF756A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/0743.image_5F00_thumb7_5F00_67BF756A.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image_thumb7" border="0" alt="image_thumb7" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/2313.image_thumb7_thumb_777F0A6E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/2313.image_5F00_thumb7_5F00_thumb_5F00_777F0A6E.png" width="820" height="497" /></a></pre>
  </div>

  <p class="csharpcode"><font face="Segoe UI">g) Now your Solution should look more like below (few more references might have been inadvertently added)</font></p>

  <pre> </pre>

  <pre><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/5226.image_thumb3_352BF22B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/5226.image_5F00_thumb3_5F00_352BF22B.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image_thumb3" border="0" alt="image_thumb3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/3073.image_thumb3_thumb_1A13231D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/3073.image_5F00_thumb3_5F00_thumb_5F00_1A13231D.png" width="247" height="533" /></a></pre>
  

  <pre> </pre>

  <pre><font color="#333333" face="Segoe UI">h) Right-click the project in Visual Studio and add the Service Reference for the Organization.svc</font></pre>

  <pre><font color="#333333" face="Segoe UI"></font> </pre>

  <pre><font color="#333333" face="Segoe UI"></font> </pre>

  <pre><font color="#333333" face="Segoe UI">i) Open the interface IService1.cs and replace the ServiceContract with the code below:</font></pre>

  <pre> </pre>

  <div class="csharpcode">
    <pre class="alt">[ServiceContract]</pre>

    <pre>    <span class="kwrd">public</span> <span class="kwrd">interface</span> IService1</pre>

    <pre class="alt">    {</pre>

    <pre> </pre>

    <pre class="alt">        [OperationContract]</pre>

    <pre>        <span class="kwrd">string</span> GetMessage();</pre>

    <pre class="alt"> </pre>

    <pre>        [OperationContract]</pre>

    <pre class="alt">        List&lt;Entities&gt; GetEntityData();</pre>

    <pre> </pre>

    <pre class="alt"> </pre>

    <pre>        [OperationContract]</pre>

    <pre class="alt">        List&lt;Views&gt; GetViewData(<span class="kwrd">int</span> SelectedEntity);</pre>

    <pre> </pre>

    <pre class="alt">        [OperationContract]</pre>

    <pre>        DataSet GetCompleteData(<span class="kwrd">string</span> _SavedQueryId);</pre>

    <pre class="alt"> </pre>

    <pre>    }</pre>
  </div>
  </div>

<p>j) Now we need to implement the Service1.svc, copy the below code (make appropriate changes for your OrganizationUri i.e. Organization.svc )</p>

<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> Service1 : IService1
    {
        <span class="kwrd">public</span> List&lt;Entities&gt; GetEntityData()
        {
        ClientCredentials Credentials = <span class="kwrd">new</span> ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        <span class="rem">//This URL needs to be updated to match the servername and Organization for the environment. </span>

        Uri OrganizationUri = <span class="kwrd">new</span> Uri(<span class="str">&quot;https://DPM2012/TailspinToysDB/XRMServices/2011/Organization.svc&quot;</span>);
        List&lt;Entities&gt; EntityList = <span class="kwrd">new</span> List&lt;Entities&gt;();
        Uri HomeRealmUri = <span class="kwrd">null</span>;
        <span class="kwrd">using</span> (OrganizationServiceProxy serviceProxy = <span class="kwrd">new</span> OrganizationServiceProxy(OrganizationUri, HomeRealmUri, </pre>

<pre class="csharpcode">        Credentials, <span class="kwrd">null</span>))
        {

            Microsoft.Xrm.Sdk.IOrganizationService service = serviceProxy <span class="kwrd">as</span> Microsoft.Xrm.Sdk.IOrganizationService;

            RetrieveAllEntitiesRequest request = <span class="kwrd">new</span> RetrieveAllEntitiesRequest()
            {
                EntityFilters = EntityFilters.Attributes,
                RetrieveAsIfPublished = <span class="kwrd">true</span>
            };

            <span class="rem">// Retrieve the MetaData.</span>
            RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)serviceProxy.Execute(request);

            <span class="kwrd">foreach</span> (EntityMetadata currentEntity <span class="kwrd">in</span> response.EntityMetadata)
            {
                <span class="kwrd">if</span> (currentEntity.IsCustomizable.Value == <span class="kwrd">true</span>)
                {
                    <span class="kwrd">foreach</span> (AttributeMetadata currentAttribute <span class="kwrd">in</span> currentEntity.Attributes)
                    {

                        Entities e = <span class="kwrd">new</span> Entities();
                        e.MyProperty = currentEntity.LogicalName;
                        e.MyProperty1 = currentEntity.ObjectTypeCode.Value.ToString();

                        <span class="kwrd">if</span> (EntityList.Where(en =&gt; en.MyProperty.Equals(e.MyProperty) &amp;&amp; </pre>

<pre class="csharpcode">                        en.MyProperty1.Equals(e.MyProperty1)).Count() == 0)
                        {
                            EntityList.Add(e);
                        }
                    }
                }
            }

        }
        <span class="kwrd">return</span> EntityList;
        }

        <span class="kwrd">public</span> List&lt;Views&gt; GetViewData(<span class="kwrd">int</span> paramSelectedEntity)
        {
        ClientCredentials Credentials = <span class="kwrd">new</span> ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        <span class="rem">//This URL needs to be updated to match the servername and Organization for the environment. </span>

        Uri OrganizationUri = <span class="kwrd">new</span> Uri(<span class="str">&quot;https://dpm2012/TailspinToysDB/XRMServices/2011/Organization.svc&quot;</span>);

        Uri HomeRealmUri = <span class="kwrd">null</span>;
        List&lt;Views&gt; ViewsList = <span class="kwrd">new</span> List&lt;Views&gt;();

        <span class="kwrd">using</span> (OrganizationServiceProxy serviceProxy = <span class="kwrd">new</span> OrganizationServiceProxy(OrganizationUri, HomeRealmUri, </pre>

<pre class="csharpcode">        Credentials, <span class="kwrd">null</span>))
        {
            serviceProxy.EnableProxyTypes();

            Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

            <span class="rem">// Retrieve Views</span>
            QueryExpression mySavedQuery = <span class="kwrd">new</span> QueryExpression
            {
                ColumnSet = <span class="kwrd">new</span> ColumnSet(<span class="str">&quot;savedqueryid&quot;</span>, <span class="str">&quot;name&quot;</span>, <span class="str">&quot;querytype&quot;</span>, <span class="str">&quot;isdefault&quot;</span>, <span class="str">&quot;returnedtypecode&quot;</span>, </pre>

<pre class="csharpcode">                <span class="str">&quot;isquickfindquery&quot;</span>),
                EntityName = SavedQuery.EntityLogicalName,
                Criteria = <span class="kwrd">new</span> FilterExpression
                {
                    Conditions =
        {
                
            <span class="kwrd">new</span> ConditionExpression
            {
                AttributeName = <span class="str">&quot;returnedtypecode&quot;</span>,
                Operator = ConditionOperator.Equal,
                Values = {paramSelectedEntity}
            }
        }
                }
            };
            RetrieveMultipleRequest retrieveSavedQueriesRequest = <span class="kwrd">new</span> RetrieveMultipleRequest { Query = mySavedQuery };

            RetrieveMultipleResponse retrieveSavedQueriesResponse = </pre>

<pre class="csharpcode">            (RetrieveMultipleResponse)serviceProxy.Execute(retrieveSavedQueriesRequest);

            DataCollection&lt;Entity&gt; savedQueries = retrieveSavedQueriesResponse.EntityCollection.Entities;
                
            <span class="kwrd">foreach</span> (Entity ent <span class="kwrd">in</span> savedQueries)
            {
                SavedQuery rsq = (SavedQuery)ent;
                <span class="kwrd">if</span> (rsq.IsDefault == <span class="kwrd">true</span>)
                {
                    Views e = <span class="kwrd">new</span> Views();
                    e.MyProperty = rsq.Name.ToString();
                    e.MyProperty1 = rsq.Id.ToString();
                    ViewsList.Add(e);
                }
            }
        }

        <span class="kwrd">return</span> ViewsList;           

        }

        <span class="kwrd">public</span> DataTable convertEntityCollectionToDataTable(EntityCollection BEC)
        {
            DataTable dt = <span class="kwrd">new</span> DataTable();
            <span class="kwrd">int</span> total = BEC.Entities.Count;
            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; total; i++)
            {
                DataRow row = dt.NewRow();
                Entity myEntity = (Entity)BEC.Entities[i];
                var keys = myEntity.Attributes.Keys;
                <span class="kwrd">foreach</span> (var item <span class="kwrd">in</span> keys)
                {
                    <span class="kwrd">string</span> columnName = item;
                    <span class="kwrd">string</span> <span class="kwrd">value</span> = getValuefromAttribute(myEntity.Attributes[item]);
                    <span class="kwrd">if</span> (dt.Columns.IndexOf(columnName) == -1)
                    {
                        dt.Columns.Add(item, Type.GetType(<span class="str">&quot;System.String&quot;</span>));
                    }
                    row[columnName] = <span class="kwrd">value</span>;
                }
                dt.Rows.Add(row);
            }
            <span class="kwrd">return</span> dt;
        }

        <span class="kwrd">private</span> <span class="kwrd">string</span> getValuefromAttribute(<span class="kwrd">object</span> p)
        {
            <span class="kwrd">if</span> (p.ToString() == <span class="str">&quot;Microsoft.Xrm.Sdk.EntityReference&quot;</span>)
            {
                <span class="kwrd">return</span> ((EntityReference)p).Name;
            }
            <span class="kwrd">if</span> (p.ToString() == <span class="str">&quot;Microsoft.Xrm.Sdk.OptionSetValue&quot;</span>)
            {
                <span class="kwrd">return</span> ((OptionSetValue)p).Value.ToString();
            }
            <span class="kwrd">if</span> (p.ToString() == <span class="str">&quot;Microsoft.Xrm.Sdk.Money&quot;</span>)
            {
                <span class="kwrd">return</span> ((Money)p).Value.ToString();
            }
            <span class="kwrd">if</span> (p.ToString() == <span class="str">&quot;Microsoft.Xrm.Sdk.AliasedValue&quot;</span>)
            {
                <span class="kwrd">return</span> ((Microsoft.Xrm.Sdk.AliasedValue)p).Value.ToString();
            }
            <span class="kwrd">else</span>
            {
                <span class="kwrd">return</span> p.ToString();
            }
        }

        <span class="kwrd">public</span> DataSet GetCompleteData(<span class="kwrd">string</span> _strSavedQueryId)
        {
        DataSet ds = <span class="kwrd">new</span> DataSet();

        Guid _SavedQueryId = <span class="kwrd">new</span> Guid(_strSavedQueryId);

        ClientCredentials Credentials = <span class="kwrd">new</span> ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        <span class="rem">//This URL needs to be updated to match the servername and Organization for the environment. </span>

        Uri OrganizationUri = <span class="kwrd">new</span> Uri(<span class="str">&quot;https://dpm2012/TailspinToysDB/XRMServices/2011/Organization.svc&quot;</span>);

        Uri HomeRealmUri = <span class="kwrd">null</span>;


        <span class="kwrd">using</span> (OrganizationServiceProxy serviceProxy = <span class="kwrd">new</span> OrganizationServiceProxy(OrganizationUri, HomeRealmUri, </pre>

<pre class="csharpcode">        Credentials, <span class="kwrd">null</span>))
        {
            serviceProxy.EnableProxyTypes();

            Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

            ColumnSet cSet = <span class="kwrd">new</span> ColumnSet(<span class="str">&quot;savedqueryid&quot;</span>, <span class="str">&quot;fetchxml&quot;</span>);

            SavedQuery rsq = (SavedQuery)service.Retrieve(SavedQuery.EntityLogicalName, _SavedQueryId, cSet);

            RetrieveMultipleRequest req = <span class="kwrd">new</span> RetrieveMultipleRequest();
            FetchExpression fetch = <span class="kwrd">new</span> FetchExpression(rsq.FetchXml);
            req.Query = fetch;
            RetrieveMultipleResponse resp = (RetrieveMultipleResponse)service.Execute(req);
            DataTable ObjDT = convertEntityCollectionToDataTable(resp.EntityCollection);
            ds.Tables.Add(ObjDT);

        }
        <span class="kwrd">return</span> ds;
        }
    }</pre>


<p>k) Now the CRM WCF Service is ready and we can publish it at IIS. The steps to publish any WCF service can be found easily over web. Starters can refer to <a title="https://debugmode.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/" href="https://debugmode.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/">https://debugmode.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/</a>. Skip the Service creation steps from this blog just refer to Publishing steps and also ensure to test it locally using a local Client.</p>

<p>If you have reached here successfully, the battle is almost won <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6644.wlEmoticon-smile_1618FB18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6644.wlEmoticon_2D00_smile_5F00_1618FB18.png" /></p>

<p> </p>

<p><strong>2) Now we just need to create a simple SharePoint 2010 Visual Web Part to consume this service as per need.</strong></p>

<p>a) Use Visual Studio 2010 to create a new Visual Web Part project.</p>

<p>b) Right Click the project and Add the Service Reference for our CRM Service published in Step 1.</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/1488.image_thumb13_77DB1796.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/1488.image_5F00_thumb13_5F00_77DB1796.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image_thumb13" border="0" alt="image_thumb13" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6114.image_thumb13_thumb_6F0B0F4A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6114.image_5F00_thumb13_5F00_thumb_5F00_6F0B0F4A.png" width="427" height="349" /></a></p>

<p> </p>

<p>c) Add the following code to VisualWebPart1UserControl.ascx :</p>

<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span><span class="kwrd">=&quot;ddlEntityList&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoPostBack</span><span class="kwrd">=&quot;True&quot;</span> 
<span class="attr">OnSelectedIndexChanged</span><span class="kwrd">=&quot;ddlEntityList_SelectedIndexChanged&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:DropDownList</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span><span class="kwrd">=&quot;ddlViewsList&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoPostBack</span><span class="kwrd">=&quot;True&quot;</span> 
<span class="attr">OnSelectedIndexChanged</span><span class="kwrd">=&quot;ddlViewsList_SelectedIndexChanged&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">asp:DropDownList</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span><span class="kwrd">=&quot;gdEntity&quot;</span> <span class="attr">ViewStateMode</span><span class="kwrd">=&quot;Disabled&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="kwrd">/&gt;</span></pre>

<p>d) Add the following code to VisualWebPart1UserControl.ascx.cs:</p>

<div align="left">
  <pre class="csharpcode"><span class="kwrd">       protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
        {
            <span class="kwrd">if</span> (!IsPostBack)
            {
                Service1Client proxy = <span class="kwrd">new</span> Service1Client();

                ddlEntityList.DataSource = proxy.GetEntityData();
                ddlEntityList.DataTextField = <span class="str">&quot;MyProperty&quot;</span>;
                ddlEntityList.DataValueField = <span class="str">&quot;MyProperty1&quot;</span>;
                ddlEntityList.DataBind();
            }
        }

        <span class="kwrd">protected</span> <span class="kwrd">void</span> ddlEntityList_SelectedIndexChanged(<span class="kwrd">object</span> sender, EventArgs e)
        {
            ddlViewsList.Items.Clear();
            <span class="kwrd">int</span> index = Convert.ToInt32(ddlEntityList.SelectedValue);
            Service1Client proxy = <span class="kwrd">new</span> Service1Client();

            ddlViewsList.DataSource = proxy.GetViewData(index);
            ddlViewsList.DataTextField = <span class="str">&quot;MyProperty&quot;</span>;
            ddlViewsList.DataValueField = <span class="str">&quot;MyProperty1&quot;</span>;
            ddlViewsList.DataBind();


        }

        <span class="kwrd">protected</span> <span class="kwrd">void</span> ddlViewsList_SelectedIndexChanged(<span class="kwrd">object</span> sender, EventArgs e)
        {            
            <span class="kwrd">string</span> str = ddlViewsList.SelectedValue;
            Service1Client proxy = <span class="kwrd">new</span> Service1Client();
            gdEntity.DataSource = proxy.GetCompleteData(str);
            gdEntity.DataBind();
        }</pre>
</div>

<p></p>

<p>e) Right click the Project and deploy to the SharePoint Site.</p>

<p>f) Go to the SharePoint 2010 Site and add the Visual Web Part to a page where you want to display the Web Part. And ‘Bingo’. You should see the something like this:</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/7356.image_thumb29_142859B7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/7356.image_5F00_thumb29_5F00_142859B7.png"><img style="margin: 0px; border: 0px currentcolor; display: inline; background-image: none;" title="image_thumb29" border="0" alt="image_thumb29" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6675.image_thumb29_thumb_120B5AEE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6675.image_5F00_thumb29_5F00_thumb_5F00_120B5AEE.png" width="822" height="229" /></a></p>

<p> </p>

<p>This SharePoint Web Part code above is pretty basic in nature for now, but I am sure you can improve upon this sample code – you know, things like:</p>

<ul>
  <li>When not to show the ‘View’ Drop Down when the Entity is refreshed. </li>

  <li>Or when there is no result set we must show appropriate result rather than the Yellow screen of death.</li>

  <li>Or you want to filter the Grid by removing certain columns from the dataset or renaming the column Header etc.</li>
</ul>

<p>I leave all it all up to you, as the sample is attached. Use it/Break it and Enjoy !!!</p>

<h4> </h4>

<h4>Food for thought</h4>

<p>1) In principle this should work for MOSS 2007, for those who are still on it <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/57/92/metablogapi/6644.wlEmoticon-smile_1618FB18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-57-92-metablogapi/6644.wlEmoticon_2D00_smile_5F00_1618FB18.png" /></p>

<p>2) In SharePoint 2013, we can merge the WCF code implementation within the SharePoint web part itself.</p>

<p>You can <strong>download the complete sample</strong> from <a href="https://sdrv.ms/11XgPOE">here</a>.</p>

<p> </p>

<h4>Code References</h4>

<p><a title="https://mscrmbi.blogspot.com/2012/02/crm-2011-convert-entitycollection-to.html" href="https://mscrmbi.blogspot.com/2012/02/crm-2011-convert-entitycollection-to.html">https://mscrmbi.blogspot.com/2012/02/crm-2011-convert-entitycollection-to.html</a> </p>

<p><a title="https://msdn.microsoft.com/en-us/library/gg695790.aspx" href="https://msdn.microsoft.com/en-us/library/gg695790.aspx">https://msdn.microsoft.com/en-us/library/gg695790.aspx</a></p>

<p> </p>

<p>Hope this helps a needy soul! If it does, please leave your comment/feedback. </p>

<p> </p>

<p>Cheers!</p>]]></content:encoded>
    </item>
  </channel>
</rss>