Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to make a WCF Rest service inside SharePoint. I'm using webHttpBinding as the binding and "WebGet" attributes on my service methods. I deployed in a standard web application and it worked very well. Then, I deployed to SharePoint (ISAPI folder) and didn't work. I googled about it and the unique solution I found is to make my WCF folder anonymous. Doing this the service worked fine but I need to get the user that is accesing my service.

So, is there any way to configure a WCF service using webHttpBinding as binding using authentication?

My web.config file is this:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
        <service behaviorConfiguration="Behaviour1" name="PoC.WCF.MockData">
            <endpoint address="rest" behaviorConfiguration="RestBehaviour" binding="webHttpBinding" contract="PoC.WCF.IMockData"></endpoint>
        </service>
    </services>
    <behaviors>
         <serviceBehaviors>
            <behavior name="Behaviour1">
                <serviceMetadata httpGetEnabled="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="RestBehaviour">
                 <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>

The service contract interface is this:

using System.ServiceModel;
using System.ServiceModel.Web;

namespace PoC.WCF
{
    [ServiceContract]
    public interface IMockData
    {
        [OperationContract]
        [WebGet(UriTemplate = "")]
        string DoWork();

        [OperationContract]
        [WebGet(UriTemplate = "/{message}")]
        string GetMessage(string message);
    }
}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

I get it after few days of googling and testing. The solution is very easy and you don't have to do anything in your development excepting use a factory on your service. This link explain what factory use depending on the service type: WCF Services in SharePoint Foundation 2010

So, the solution to my problem is to modify the "svc" file and add the factory you need. In my case, for a Rest service, I have to use "MultipleBaseAddressWebServiceHostFactory". This is my code:

<%@ ServiceHost 
    Service="PoC.WCF.MockData, PoC.WCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a1a45d52b868570"
    Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.