2

I have to write a content enrichment webservice which retrieves data from an specific SharePoint Site (SPSite). But my code doesn't run, if i make a new SPSite Object. Also no logging information in ULS Log.

The WCF service is hosted in IIS as an application within the SharePoint Portal Application Pool.

is it generally possible to use SharePoint SSOM in wcf service?

Here is some code nothing special:

 public ProcessedItem ProcessItem(Item item) { try { using (SPSite site = new SPSite("http://sharepointurl")) { using (SPWeb web = site.OpenWeb()) { } } } catch (Exception ex) { } } 
4
  • You can access SSOM as long as you located on sharepoint server. How you create SPSite object? Maybe you use SPContext.Current? It would be great if yo u can post code. Commented Nov 20, 2013 at 13:15
  • Do you get any exceptions? Maybe alternate access mapping are not configured? Commented Nov 20, 2013 at 15:45
  • It works now! The problem was the endpoint in the EnterpriseSearchContentEnrichmentConfiguration. I put it on localhost. Thanks for your advice with the alternate access mapping! :) Commented Nov 21, 2013 at 7:28
  • If my answer helped you then mark it please. Commented Nov 21, 2013 at 8:13

4 Answers 4

2

You have to add the Web Service to the Search Service Application, using PowerShell, and perform a full crawl in order to make it do anything. Follow Script below:

# Create and add your CEWS to IIS, before using this if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } $ssa = Get-SPEnterpriseSearchServiceApplication $config = New-SPEnterpriseSearchContentEnrichmentConfiguration $config.Endpoint = "http://localhost/ContentProcessingEnrichmentService/ContentProcessingEnrichmentService.svc" $config.InputProperties = "Author", "Filename" $config.OutputProperties = "Author" $config.SendRawData = $True $config.MaxRawDataSize = 8192 Set-SPEnterpriseSearchContentEnrichmentConfiguration –SearchApplication $ssa –ContentEnrichmentConfiguration $config 

Reference: How to: Use the Content Enrichment web service callout for SharePoint Server

0

Check you alternate access mappings.

0
 SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(web.Site.ID)) { // implementation details omitted } }); 

You can't access everything from wcf services, because by default you are doing it as anonymous with rights from current logged user. So try to elevate priviliges. Inside SPSecurity.RunWithElevatedPrivileges your code runs as app_pool account that have rights close to system account. Ofc, your services have to be installed as wsp packaged on sp's app pool:)

0

The problem was solved for me, by setting the target platform to x64 in the Build section of the Web Service project properties.

I was then able to open a site and a web using your code without elevation! However, the Web Service User is SP Farm Admin (dev machine) and the service is running on a SharePoint Server.