Search code examples
jquerywcfiiswcf-bindingwindows-authentication

WCF Configuration for Windows authentication and jQuery


I have an ASP.NET MVC application that uses Windows authentication. I'd like that application to call a WCF service that resides in that same application. However, I can't seem to get the configuration piece down for this application. Both the ASP.NET MVC and WCF service reside in the same project. Here's the configuration I have thus far:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
        <basicHttpBinding>
            <binding>
                <security mode="TransportCredentialOnly" >
                    <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <services>
        <service name="DashboardService">
            <endpoint address="" binding="basicHttpBinding" contract="MyApplication.Services.ICustomService" />
        </service>
    </services>
    <client>
        <endpoint address="" binding="basicHttpBinding" contract="MyApplication.Services.ICustomService" />
    </client>
</system.serviceModel>

I've tried to connect to the WCF service using a Service Reference in a different ASP.NET application, The method works correctly and I can return the proper data.

However, with this config, I'm getting a 400, Bad Request when I visit http://domain/myservice.svc/method. However, both http://domain/myservice.svc and http://domain/myservice.svc?wsdl work correctly.

It seems like I'm overlooking something in my WCF configuration.

Any help that can be provided is appreciated.


Solution

  • I was able to change my configuration to use the webHttpBinding like so:

    <system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="RestEndpoint">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <webHttpBinding>
            <binding name ="WindowsRestBinding">
                <security mode ="TransportCredentialOnly">
                    <transport clientCredentialType ="Windows"/>
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
        <service name="MyApplication.Services.CustomService">
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="WindowsRestBinding" contract="MyApplication.Services.ICustomService" behaviorConfiguration="RestEndpoint" />
        </service>
    </services>