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)
        {

        }
    }

migrated from stackoverflow.com Nov 21 '13 at 22:46

This question came from our site for professional and enthusiast programmers.

  • 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. – Yevgeniy.Chernobrivets Nov 20 '13 at 13:15
  • Do you get any exceptions? Maybe alternate access mapping are not configured? – Yevgeniy.Chernobrivets Nov 20 '13 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! :) – user2988273 Nov 21 '13 at 7:28
  • If my answer helped you then mark it please. – Yevgeniy.Chernobrivets Nov 21 '13 at 8:13
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.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy