Jeffrey Kevin Pry
Jeffrey Kevin Pry

Reputation: 3296

Using WCF REST services with Unity on IIS

I am trying to use dependency injection with WCF REST (WebGet) and am having trouble understanding where I would use Unity to build my object to host the web service.

I have seen many examples all over the web, but they seem to all be hosting the service in a console app or Windows service.

Currently my config file looks like this:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Services.MyRestService">
        <endpoint address="http://localhost:8732/api" binding="webHttpBinding" contract="Shared.Services.IMyRestService"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

Currently the way it works is using the built in WCF service host in Visual Studio. However, I'd like to run this in IIS and use Unity to configure my container. Now I am using "bastard injection" to get the job done, but would like to use Unity to supply the data provider implementation, etc.

My question is, what configuration changes do I need to make to host this in IIS and also where do I configure the container and let IIS know about it.

There are no SVC files as this is a WCF Service Library.

Thanks in advance!

Upvotes: 1

Views: 1662

Answers (2)

Claudio Sanchez
Claudio Sanchez

Reputation: 43

With WCF REST you would use WebServiceFactory and WebServiceHost as your base classes.

Upvotes: 0

CodingWithSpike
CodingWithSpike

Reputation: 43698

The "normal" way to do this would be to implement a custom IInstanceProvider WCF extension point, and add it through configuration. I've only done this with regular SOAP endpoints, but I think it would work the same for WebAPI.

Couple links that might help:

The 2nd link covers some of the XML configuration stuff for adding a custom IInstanceProvider to the behavior.

Upvotes: 2

Related Questions