tags:

views:

281

answers:

1

I have a REST WCF service. Its using a webHttpBinding and the configuration looks like this:

<service name="IndexingService.RestService" behaviorConfiguration="IndexingService.Service1Behavior">
    <endpoint
      address=""
      binding="webHttpBinding"
      bindingConfiguration="CustomMapper"
      contract="IndexingService.IIndexingService"
      behaviorConfiguration="webby"/>
</service>

The CustomMapper is used to apply a custom WebContentTypeMapper, which I tried to configure like this:

<binding name="CustomMapper">
        <webMessageEncoding webContentTypeMapperType="IndexingService.CustomContentTypeMapper, IndexingService" />
        <httpTransport manualAddressing="true" />
</binding>

But I cannot figure out where in my web.config I should insert these lines:

  • If I put these lines below I get an error, because webMessageEncoding is not a recognized element.
  • If I put the lines below a custom binding tag, I get an error that wsHttpBinding does not have a CustomMapper defined!?

Can somebody explain how to use a custom type mapper together with webHttpBinding?

+2  A: 

If you define a complete custom binding (as you do here with CustomMapper):

<binding name="CustomMapper">
   <webMessageEncoding webContentTypeMapperType=
             "IndexingService.CustomContentTypeMapper, IndexingService" />
   <httpTransport manualAddressing="true" />
</binding>

then you need to use that custom binding in your service endpoint - not webHttpBinding! This config section does not define just a bindingConfiguration!

Try this config here:

<system.serviceModel>
  <bindings>
    <customBinding>
       <binding name="CustomMapper">
          <webMessageEncoding webContentTypeMapperType=
                 "IndexingService.CustomContentTypeMapper, IndexingService" />
          <httpTransport manualAddressing="true" />
       </binding>
    </customBinding>
  </bindings>
  <services>
    <service name="IndexingService.RestService"   
             behaviorConfiguration="IndexingService.Service1Behavior">
        <endpoint
           address=""
            binding="customBinding"
            bindingConfiguration="CustomMapper"
            contract="IndexingService.IIndexingService"
            behaviorConfiguration="webby"/>
     </service>
  </services>
</system.serviceModel>

Marc

marc_s
If I try this, I get the following error: Configuration binding extension 'system.serviceModel/bindings/CustomMapper' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Achim
Sorry, my mistake - has been a while since I did that :-) Updated my answer. The endpoint needs to be binding=customBinding bindingConfiguration must map to CustomMapper
marc_s