Preparing Developer Virtual Machine for SharePoint 2016 Preview

In anticipation for the SharePoint Server 2016 Preview release this month of August 2015, I have prepared a Hyper-V virtual machine for development and evaluation purposes.

System Requirements
http://blogs.technet.com/b/wbaer/archive/2015/05/12/what-s-new-in-sharepoint-server-2016-installation-and-deployment.aspx

Scenario Deployment type and scale Processor RAM Hard disk
Database server running a single SQL instance Development or evaluation installation with
the minimum recommended services
64-bit, 4 cores 12-16 GB 80 GB for system drive
100 GB for second drive

My setup:

Host
OS: Windows 10 Pro
Desktop
Intel Core i5 @ 2.67Ghz 4 Logical Processors
120GB Intel Solid State Drive for VM Disks only
16GB RAM

Hyper-V Virtual Machine
2 Logical processors
12GB RAM

Windows Server 2012R2 with Update
SQL Server 2014 with Service Pack 1
Visual Studio 2015
Chrome

My Software Preparation:

I recently upgraded to Windows 10 and I am enjoying it including the new Start Menu with Tiles and Cortana.

I installed the Hyper-V Manager feature
Control Panel > Programs and Features > Turn On windows features or off
Check off ‘Hyper-V’

Hyper-V

I ran Hyper-V Manager and create a new Virtual Machine and went through the wizard and allocated system resources such as 2 logical processors, location of the VM disk in my solid state drive, and 12 GB of ram. I highly recommend solid state drives for SharePoint VMs as I notice a big performance gain with much higher IOPS.

Note that according to minimum requirements of 4 processors, I will try to settle with only 2 logical processors but if needed I’ll bump up to 4 logical processors. I plan on saving VM system resources by turning off services in Central Administration ‘Services on Server’ such as SharePoint Server Search, Excel Calculation services, Access Services, Machine Translation Service until I want to use them.

I had installed the Windows Server 2012 R2 operating system through .ISO image file.

After installation is complete and booting up Windows Server, I ensured to add roles and features with
Active Directory Domain Services
Web role and app role.
Application Server role

Windows Server Add Role

Next, I installed SQL Server 2014. I just include all the features.

Next, I installed Visual Studio 2015 to develop SharePoint apps/add-ins. I noticed that the install options, you can choose Office Developer tools. Note that you shouldn’t expect it to support SharePoint 2016, but my guess it will to some extent such as simple web parts and list and library deployment.

To download Office Tools separately, visit https://www.visualstudio.com/features/office-tools-vs

Now wait for the SharePoint 2016 Preview download hopefully sometime this month of August.

SharePoint 2013 Workflow Integration with the WaitForCustomEvent Activity

Implementing an integration scenario with SharePoint 2013 Workflows using WaitForCustomEvent Activity in Visual Studio 2012 Technical Requirement: Integrate a SharePoint workflow with another application to call into the application and wait for a response with data.

Applicable business scenarios

  • A document management approval workflow notifies a CRM system of a customer engagement and provides a reference number back to the workflow.
  • A SharePoint workflow assigns and emails an end user to do some work in another application. The end user goes to the other application to do this work and it notifies the workflow of completion and other application data. The SharePoint workflow continues.

The following is an implementation flow that is applied to the above business scenario.

  1. The workflow instance calls an external application through a RESTful service passing correlating information and the custom wait event name.
  2. Workflow is in a wait state by the WaitForCustomEvent.
  3. The external application executes its relevant business logic and is then ready to notify the workflow through the SharePoint API by passing correlating information, event name and any event args (e.g. data).
  4. The workflow custom wait event handles the call and continues execution with the given event args. At this point, the workflow status can be set.
WaitForCustomEvent 2

High level development

  1. In Visual Studio 2013
    • Create a Workflow Custom Activity project item.
    • Deploy solution to a site.
  2. In SharePoint Designer 2013
    • Create a SharePoint 2013 workflow. The deployed activity will apear in the Actions menu
    • Add the custom action to the workflow design surface.
    • Publish workflow

Updating workflow custom activity and redeploy steps

  1. Create Workflow in SharePoint Designer 2013
    • Clear SP Designer website cache
  2. Create Workflow Activity in Visual Studio 2012
  3. Create external application to receive and publish the even back to the running workflow instance.

The WaitForCustomEvent Activity

This activity is part of the toolbox when you want to create a Custom Workflow Activity in Visual Studio 2012.

WaitForCustomEvent 3

When deployed to the SharePoint server, it will show up as a custom action in SharePoint Designer 2013. This activity has an input of EventName and an output of Result.

WaitForCustomEvent 12

SharePoint Client Side Object Model: WorkflowInstanceService.PublishCustomEvent

In the external application, leveraging the SharePoint Client Side Object Model, use the WorkflowInstanceService.PublishCustomEvent method to call to the waiting workflow instance to continue. This activity would handle the event is by a CSOM API call using the PublishCustomEvent method.

Parameter Description Type
instance The instance of a workflow that is running. WorkflowInstance
eventName The event name that would be declared in the WaitForCustomEvent activity String
payload Data that would be passed to the workflow. String

As you can see, the EventName input is associated to the eventName parameter and the Result output to the payload parameter. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflowservices.workflowinstanceservice.publishcustomevent.aspx

WorkflowServicesManager workflowServiceManager = new WorkflowServicesManager(web);
var workflowInstanceService = workflowServiceManager.GetWorkflowInstanceService();
workflowInstanceService.PublishCustomEvent(workflowInstance, "CustomEventName", "Eventpayload:value;key:value");

Sample code on the use of this method is in  Sohel Blog post

Creating the Workflow Custom Activity in Visual Studio 2012

    1. Create new project SharePoint 2013 – Empty Project
    2. Right click on the project > Add new item > Select Workflow Custom ActivityWaitForCustomEvent 5
    3. Click on the xaml file and see the designer surface.
    4. Open the Toolbox pane
    5. Drag and drop the WaitForCustomEvent activity on to the designer surface. I have also added WriteToHistory activity for debugging/tracing purposes. WaitForCustomEvent 6
    6. Create arguments to make the design of this custom workflow activity dynamic and reusable in Sharepoint Designer workflows. At the bottom of the designer surface, click on the Arguments tab.WaitForCustomEvent 7

      Set “EventName” as an input argument and the “EventOuput” as the output argument. To give you an idea of what we are trying to achieve by “dynamic” here is a peak of how it will be used in SharePoint Designer workflow. The following blue text are placeholders for literal values or variables.

      WaitForCustomEvent 11 WaitForCustomEvent 9

    7. So now let’s get back to setting up these arguments in Visual Studio 2012. Click on the WaitForCustomEvent activity properties pane. Enter “EventName” argument for the EventName input Enter “EventOuput” argument for the Result ouput.WaitForCustomEvent 10
    8. Let’s surface these arguments to SharePoint Designer to look likeWaitForCustomEvent 8 Click on the .actions4 file. Setup as follows:
      <Action Name="WaitEventActivity" ClassName="WaitEvent.WaitEventActivity" Category="Custom" AppliesTo="all">
        <RuleDesigner Sentence="Wait Event Name %1 ( Event Args %2 )">
          <FieldBind Field="EventName" Text="Event Name" Id="1"
          DesignerType="TextBox"
          DisplayName="Event Name triggered from an external system" />
          <FieldBind Field="EventOutput" Text="Event Output" Id="2"
          DesignerType="TextBox" DisplayName="Event ouput from an external system"   />
        </RuleDesigner>
        <Parameters>
          <Parameter Name="EventName" Type="System.String, mscorlib" Direction="Optional"
          DesignerType="TextBox"
          Description="Event Name" />
          <Parameter Name="EventOuput" Type="System.String, mscorlib" Direction="Out"
          DesignerType="TextBox"
          Description="Event Output" />
        </Parameters>
      </Action>
      

Note: you can find more examples in the workflow15.actions4 file. These are all the out of the box actions. They are located at C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\1033\Workflow

    1. Deploy the solution to your SharePoint site.
      This is deployed as a farm solution and activate the feature at the web scope.
    2.  Open SharePoint Designer 2013 and open the site where you had activated the feature with the WaitForCustomEvent activity.
    3. Create a new Workflow in 2013 workflow platform
    4. In the ribbon, click Action > Add the Call HTTP Web Service to make a call to the external application through a RESTful service such that the necessary business logic will be executed.
      Pass correlating information and custom event name as query. This will be used to by the external application to call back to the workflow.
    5. In the ribbon, click Action and you should see in the Custom group as defined in .actions4 file.
      WaitForCustomEvent 12
    6. Create the following workflow with using the actions Set Workflow Status, Log to History List WaitForCustomEvent 13 

Creating a Mock External Application

This application will serve as a mock external system or application noted as “3” in the diagram above. This application will serve two purposes:

  • Self-hosted RESTful services that wraps the business logic of which the workflow can call into. You may to choose to host in IIS web server.
  • This business logic will make a call to publish a custom event notification to the running workflow instance using the SharePoint .NET Client Side Object Model.

Reference:
How to create Self-Host a Web API
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api

  1. Add New Project
  2. Select Console Application
  3. Right-click the Project > Manage NuGet Packages
  4. Install Microsoft ASP.NET Web API Self Host
  5. Add assembly references > browse C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\
    • Microsoft.SharePoint.Client.WorkflowServices
    • Microsoft.SharePoint.Client.Workflow
    • Microsoft.SharePoint.Client.Runtime
    • Create a class and method
  6. Create a business class with the method
    PublishCustomWorkflowEvent(string url, string listTitle, string documentTitle, string eventName, string eventArgs)
    {
      using (ClientContext ctx = new ClientContext(url))
      {
        ctx.Credentials = new NetworkCredential("\\ ", "");
        // Best practice: retrive credentials in a secured credentials store.
    
        Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager workflowServiceManager = new Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager(ctx, ctx.Web);
        var workflowInstanceService = workflowServiceManager.GetWorkflowInstanceService();
    
        List list = ctx.Web.Lists.GetByTitle(listTitle);
        int itemId = 1;
    
        CamlQuery query = new CamlQuery();
        query.ViewXml =@""
        + documentTitle
        + "";
    
        ctx.Load(list);
        ctx.ExecuteQuery();
    
        ListItemCollection listItems = list.GetItems(query);
        ctx.Load(listItems);
        ctx.ExecuteQuery();
        if (listItems.Count > 0)
          itemId = listItems[0].Id;
    
        var workflowInstances = workflowInstanceService.EnumerateInstancesForListItem(list.Id, itemId);
    
        ctx.Load(workflowInstances);
        ctx.ExecuteQuery();
    
        // Once we get the workflow Instance, we can get the instance properties as shown below. Any properties in Workflow Initiation form will also be available:
        if (workflowInstances.Count > 0)
        {
        foreach (WorkflowInstance instance in workflowInstances)
        {
          WorkflowStatus status = instance.Status;
          if (instance.Properties.Count > 0)
          {
            var itemUrl = instance.Properties["Microsoft.SharePoint.ActivationProperties.CurrentItemUrl"];
    
            Console.WriteLine("Internal Status: " + instance.Status);
            Console.WriteLine(" Item Url: " + itemUrl);
            Console.WriteLine(" Workflow User Status: " + instance.UserStatus);
            string userStatus = instance.UserStatus;
            var propertyValue = instance.Properties["Microsoft.SharePoint.ActivationProperties.ItemId"];
    
            workflowInstanceService.PublishCustomEvent(instance, eventName, eventArgs);
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Event Args: " + eventArgs);
         }
        } // end foreach workflowInstances
      }
    }
    
    
  7. Create a RESTful method in a controller class inherited from the APIController.
    [HttpGet]
    public string DoSomeWork(string url, string listTitle, string documentTitle, string eventName)
    {
      string output = string.Emptyy;
      // DO SOME WORK
    
      // publish custom event to running workflow instance
      PublishCustomWorkflowEvent(url, listTitle, documentTitle, eventName, eventArgs);
     return output;</pre>
    }
    

SharePoint Designer 2013 | Publishing 2013 Workflow Error

Using SharePoint Designer 2013, I create and publish a simple custom workflow (2013 platform). I get the following within the error message:

“There was no endpoint listening at net.pipe://localhost/SecurityTokenServiceApplication/appsts.svc that could accept the message.”

Background:

  • I am able to browse to http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc with no issues or errors showing.
  • I have installed Worfklow Manager (and update) on a WFE server in a 3 tier setup.
  • I am trying to publish this through a domain account which was not used to install, but is still local administrator and Site Collection administrator.
  • The net.pipe binding exists in IIS web site for SharePoint Web Services
  • Windows Server 2012, installed all WF updates, SP server updates, SP Designer update

Solution:

Windows Services -> Start the Net.Pipe Listener Adapter service

Service Description: Receives activation requests over the net.pipe protocol and passes them to the Windows Process Activation Service.

I just stumbled upon this service by associating the name “Net.Pipe” and the error message containing “There was no endpoint listening at net.pipe://…”

What is “net.pipe”?

netNamedPipeBinding binding, which provides cross-process communication on the same machine. Named pipes do not work across machines.”

Common SharePoint Web Part Errors

The following are some of the common web part errors that I just wanted to summarize and provide the general solution.

Error Message:

A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.

Image

OR

A Web Part or Web Form Control on this Page cannot be displayed or imported. The type DateTimeWebPart.DateTimeWebPart.DateTimeWebPart, DateTimeWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2bfd9e5fd3b67b15 could not be found or it is not registered as safe.

OR

An error occurred when previewing the Web Part.

Ways to reproduce error

  • Preview web part by Site Settings > Web parts (Galleries) > Click web part list item; OR
  • Insert web part to a page; OR
  • View a page that previously inserted the web part.

The files in question

Image

1) .cs

Image

2) .webpart

Image

3) .spdata
(hidden – must ‘show all files’ at the Visual Studio project level)

Image

OR

Right Click <WebPart> Project item > Properties > Click Safe Control Entries

Image

4) Web.config
(IIS virtual directory, e.g. C:\inetpub\wwwroot\wss\VirtualDirectories\80)

The safe control entry is automated in deployment declared in the .spdata file.

<SafeControls>
<SafeControl Assembly=”DateTimeWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2bfd9e5fd3b67b15″ Namespace=”DateTimeWebPart.DateTimeWebPart” TypeName=”*” Safe=”True” />
</SafeControls>

5) Assembly / DLL file missing  in the Global Assembly Cache for GAC deployment (c:\windows\assembly) or virtual directory bin folder in web app deployment.

Resolution

Make sure the Namespace and Type Name are consistent across all files where indicated. Also with matching case sensitivity.

Verify web.config file and assembly in GAC or virtual directory bin folder in post deployment.

Background

What does it mean by ‘type could not be found’? What is the type?

The type in question is the class inheriting from WebPart class. In this case, it is DateTimeWebPart.DateTimeWebPart.DateTimeWebPart. Excuse my naming convention. When the .NET run time is creating an instance of the web part, the run time can not find the type; either because the assembly is missing, inaccurately referenced or misnamed.

What does it mean by ‘Is not registered as safe’?

Given that the type can be found and the type is registered in the web.config in the <SafeControls> xml node.

The safe control entries mark a web control (instantiated in the web part) such that an untrusted user has access to the web control. Or another way to look at it is that the web application trusts the web control.

Speaking at the Calgary .NET User Group this Wed Dec. 14 ’11

I’m looking forward to speaking at the Calgary .NET User group on the www.calgary.ca site.
Wed Dec 14, 2011

Presenting features, applied technologies and approaches:

SharePoint 2010
.NET Framework, ASP .NET, Windows Communication Foundation
Google Search Appliance
Arc GIS
Webtrends 
Mobile Browsing 

Click the link for event details

http://www.dotnetcalgary.com/Events/tabid/61/ModuleID/381/ItemID/9/mctl/EventDetails/Default.aspx