views:

129

answers:

1

I'm trying to host a WCF service in IIS7 that works with both Silverlight and for GET requests. I have the Silverlight endpoint working but can't work out how to create an additional endpoint on the same service that will handle GET requests from AJAX clients.

I have a second service that is for GET requests only and it works fine so my question isn't about how to set up an endpoint for a GET requests but how to set up a service that has two endpoints one for Silverlight requests and one for GET requests.

My IIS web.config has:

<system.serviceModel>
  <services>
    <service name="MyAssembly.MyService">
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
      <endpoint address="http://localhost/provisioning.svc" binding="basicHttpBinding" contract="MyAssembly.IMyService" />
      <endpoint address="http://localhost/provisioningajax.svc" binding="webHttpBinding" contract="MyAssembly.IMyService" />
    </service>
  </services>
<system.serviceModel>

The provisioning.svc and provisioningajax.svc files hold the same thing which is:

<% @ServiceHost Service="MyAssembly.MyService" %>

The provisioning.svc endpoint works with my Silverlight clients ok but I can't get the provisioningajax.svc to work. When attempting to access it I get a Runtime error and the following error message in the Application Event Log.

Exception information: Exception type: InvalidOperationException Exception message: The ChannelDispatcher at 'http://localhost/provisioning.svc' with contract(s) '"MyAssembly.IMyService"' is unable to open its IChannelListener.

+3  A: 

To use the webHttpBinding for your Ajax provisioning endpoint, you need to set up additional bits and pieces, like the "webHttp" behavior, on your server, and you need to use the WebServiceHostFactory.

Did you do that??

You'll need to add this snippet to your server-side config:

<behaviors>
    <endpointBehaviors>
      <behavior name="webHttp">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

and your SVC file used for the Ajax provisioning should be:

<%@ServiceHost language="c#" Service="MyAssembly.MyService" 
   Factory="System.ServiceModel.WebServiceHostFactory" %>

Note the "Factory=" setting - that's the key. You need to use the WebServiceHostFactory (not the straight, normal ServiceHostFactory for other binding) for webHttp.

Marc

marc_s