Enable JSON in SharePoint 2013 On-premises

Published by Shubham Bansal on

In SharePoint 2013 on-premises, by default, accessing getting the response from REST APIs in JSON format doesn’t work. We need to install WCF Data Service 5.6 to provide the support for JSON responses and will have to add the assembly references for WCF Data Services 5.6.

 

Check if WCFDataServices 5.6 is installed on the Web Front End Servers.

If it is not installed, download it from here:

http://download.microsoft.com/download/1/C/A/1CAA41C7-88B9-42D6-9E11-3C655656DAB1/WcfDataServices.exe

 

Run the setup WCFDataServices.exe and install.

After installation, Verify if the DLLs deployed for WCF Data Services are the latest (version 5.6) are installed and placed in GAC

1. Microsoft.Data.Edm

2. Microsoft.Data.Odata

3. Microsoft.Data.Services.Client

4. Microsoft.Data.Services

5. System.Spatial

 Now for adding the references to these DLLs in the web service, Execute below:

$configOwnerName = "JSONLightDependentAssembly"
$spWebConfigModClass ="Microsoft.SharePoint.Administration.SPWebConfigModification"
$dependentAssemblyPath ="configuration/runtime/*[local-name()='assemblyBinding' and namespace-uri()='urn:schemas-microsoft-com:asm.v1']"
$dependentAssemblyNameStart ="*[local-name()='dependentAssembly'][*/@name='"
$dependentAssemblyNameEnd = "'][*/@publicKeyToken='31bf3856ad364e35'][*/@culture='neutral']"
$dependentAssemblyValueStart = "<dependentAssembly><assemblyIdentity name='"
$dependentAssemblyValueEnd ="' publicKeyToken='31bf3856ad364e35' culture='neutral' /><bindingRedirect oldVersion='5.0.0.0' newVersion='5.6.0.0' /></dependentAssembly>"
$edmAssemblyName ="Microsoft.Data.Edm"
$odataAssemblyName ="Microsoft.Data.Odata"
$dataServicesAssemblyName ="Microsoft.Data.Services"
$dataServicesClientAssemblyName ="Microsoft.Data.Services.Client"
$spatialAssemblyName ="System.Spatial"
$assemblyNamesArray = $edmAssemblyName,$odataAssemblyName,$dataServicesAssemblyName,$dataServicesClientAssemblyName, $spatialAssemblyName
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
################ Adds individual assemblies ####################
For ($i=0; $i -lt 5; $i++)
{
    echo "Adding Assembly..."$assemblyNamesArray[$i]
    $dependentAssembly = New-Object $spWebConfigModClass
    $dependentAssembly.Path=$dependentAssemblyPath
    $dependentAssembly.Sequence =0 # First item to be inserted
    $dependentAssembly.Owner = $configOwnerName
    $dependentAssembly.Name =$dependentAssemblyNameStart + $assemblyNamesArray[$i] + $dependentAssemblyNameEnd
    $dependentAssembly.Type = 0 #Ensure Child Node
    $dependentAssembly.Value = $dependentAssemblyValueStart + $assemblyNamesArray[$i] + $dependentAssemblyValueEnd
    $webService.WebConfigModifications.Add($dependentAssembly)
}
###############################################################
echo "Saving Web Config Modification"
$webService.Update()
$webService.ApplyWebConfigModifications()
echo "Update Complete"

 1,202 total views,  1 views today

Care to Share?

0 Comments

Leave a Reply