Asp – Unable to host WCF service correctly in IIS7

asp.net-mvcvisual studio 2010wcf

I have a WCF Service library written in .NET 4.0. I have a WCF application (in order to host this service in IIS) within the same solution. It contains the WCF library assembly reference and a service.svc file pointing to the service from the library along with a web.config that is a replica of the WCF service library's app.config. The WCF application is set to host the service in IIS7 (the virtual directory has been set). The same solution contains an ASP.NET Webforms solution to which I have added a service reference pointing to the WCF service I hosted in IIS (as mentioned).

When i start an instance of this ASP.NET Web application, I get a message saying that "The WCF service has been hosted" and the ASP.NET application can access the data from it correctly. However, when i try and access this data via a service reference added to an MVC 2 Web Application on the same machine in a different solution (pointing to the service hosted in IIS), I get a "The remote server returned an error: (405) Method Not Allowed." protocol exception . However, the MVC application is able to access the service data if I manually invoke an instance of the WCF Application that I was using to host the WCF Service Library from the other solution.

I am using VS2010 Beta 2 as my development IDE. I have been stuck with this issue for a while now. Any help would be appreciated.

My service config is as follows:-

<system.serviceModel>
<services>
  <service behaviorConfiguration="CruxServices.BasicSearchServiceBehavior"
    name="CruxServices.BasicSearch.BasicSearch">
    <endpoint address="" binding="wsHttpBinding" name="WSBindingEndpoint" bindingConfiguration="WSBindingConfig"
      contract="CruxServices.BasicSearch.Interfaces.IPropertyListFilter">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" name="MexEndpoint"
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/CruxServices" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="CruxServices.BasicSearchServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <wsHttpBinding>
    <binding name="WSBindingConfig">
      <security mode="None">
        <transport clientCredentialType="None"/>
        <message establishSecurityContext="false"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

Best Answer

In the configuration of IIS you specify which version of the .net framework you want to use.

In this context there are 4 versions of the .net framework: 1.0, 1.1, 2.0 and 4.0

Your first problem is that IIS is not configured to run framework 4.0

You may however you may have a bigger problem, I am not sure if it is possible, you may need IIS 7.5

EDIT

Have now checked it. It will work, the only thing you need to do is to make sure that framework 4 is selected as the framework for the application pool.