First of all there are plenty of articles on the net for this but most of them are for WCF 3.5. I'm using some features of WCF 4.0 which makes the scenario a bit different.
Following is my contract:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate="x?v={value}")]
string GetData(int value);
}
Following is my service class:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
Following is my web.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
I'm not using any svc file so in Global.asax I've written the following line of code to expose my service at path 'blah'
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("blah", new WebServiceHostFactory(), typeof(Service1)));
}
Now for enabling basic authentication if I change standard endpoint in web.config as follows:
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint automaticFormatSelectionEnabled="true">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
I get the following error:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
What should I do from this point onwards to make it work? And where will I check the username/password supplied with each request?
This can't be tested in ASP.NET Development Server and for running in IIS 7.5 we have to install basic authentication and also we need to create a certificate and associate ssl binding with that application.
Doing all of that resulted in webservice methods to require basic authentication but it was working against AD.
There is no way to change it to authenticate it yourself.