WCF REST services hosted under IIS generates authentication errors RRS feed

  • Question

  • Hello,

    I'm trying host a RESTfull service using visual studio 2008 under IIS 5 with no success.


    That's what the service do (very much simple):

    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/date",

    RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]

    public string GetData()


    return string.Format("Current time: {0}", DateTime.Now.ToString());



    Using a non-config approach i defined the .svc file with the following tag:

    <%@ ServiceHost Language="C#" Debug="true" Service="WcfService2.Service1" CodeBehind="Service1.svc.cs"

    Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>


    This factory is responsible for creating an endpoint with webHttpBinding that provides the REST services.

    under hosting server: http://localhost:17562/Service1.svc/date will generate the following output:

    <string xmlns="">Current time: 4/24/2008 2:38:38 PM</string>

    which is exactly what is needed. unfortunatelly moving to IIS hosting with no changes at all generates the following error:

    http://localhost/WcfService2/Service1.svc/date - 404 not found.

    http://localhost/WcfService2/Service1.svc - "IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used."

    I've canceled the windows integrated security on IIS and hit F5+CTRL on visual studio http://localhost/WcfService2/Service1.svc - Access denied 401.

    http://localhost/WcfService2/Service1.svc/date - 404 not found.


    so then I tried a different approach - the config way. I removed the WebServiceHostFactory from the .svc file, updated IIS for windows integrated and anonymous again, and add this configuration block:




    <service name="WcfService2.Service1" behaviorConfiguration="Service1Behavior">





    contract="WcfService2.IService1" />

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />





    <behavior name="epBehavior">

    <webHttp />




    <behavior name="Service1Behavior">

    <serviceMetadata httpGetEnabled="true"/>

    <serviceDebug includeExceptionDetailInFaults="true"/>






    hit F5+CTRL again - http://localhost/WcfService2/Service1.svc returns the service default page with link to the wsdl that also works. http://localhost/WcfService2/Service1.svc/date still returns 404. I even tried creating a custom factory of my own in which I create in code an endpoint with webHttpBinding but with no sucess. I can't get the REST to work under IIS. this was also used in visual studio 2005 and generated the same errors.

    What do I do wrong here? is it the IIS 5?



    Thursday, April 24, 2008 2:52 PM

All replies