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);
}
}