none
How to add encoder and dispatcher to WCF service in Web.config RRS feed

  • Question

  • Hi

    I have a WCF Service Application, contracts are generated from WSDL (Connected Services). I also have implemented custom message encoder as a behavior and dispatcher by body element as a binding. I am having problem applying them to the service in Web.config.

    The custom message encoder works, but the dispatch by body element does not.

    My system.serviceModel block in Web.config is following:

    <system.serviceModel>
        <diagnostics performanceCounters="Default" />
        <extensions>
            <behaviorExtensions>
                <add name="CustomMessageFilter" type="WCFExtensions.Filters.FilteringEndpointBehaviorExtension, WcfExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            </behaviorExtensions>
            <bindingElementExtensions>
                <add name="CustomMessageEncoder" type="AdapterServer.CustomMessageEncoder.CustomEncodingBindingSection, AdapterServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            </bindingElementExtensions>
        </extensions>
        <bindings>
            <customBinding>
                <binding name="">
                    <CustomMessageEncoder />
                    <httpTransport />
                </binding>
            </customBinding>
        </bindings>
        <services>
            <service name="AdapterServer.Service">
                <endpoint address="" behaviorConfiguration="CustomMessageFilterBehavior" binding="customBinding" bindingConfiguration="" contract="Something.ServiceNamePortType" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="CustomMessageFilterBehavior">
                    <CustomMessageFilter />
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpBinding" scheme="http" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>


    What am i doing wrong?

    EDIT 1

    I noticed something.

    In my service class (Service.svc.cs) i have:

    namespace AdapterServer
    {
        [DispatchByBodyElementBehavior]
        public class Service : Something.ServiceNamePortType
        {
            [DispatchBodyElement("Foo", "http://foo.buu.huu")]
            public SomeResponse Foo(SomeRequest request)
            {
                ...
            }
        }
    }

    Now, in Web.config when i do:

    <service name="AdapterServer.FromWSDL.ServiceNamePortTypeClient">

    ...then the dispatch by body element works, but not the encoder. The name value is from WSDL, the interface WCF generated.

    But when i change it to:

    <service name="AdapterServer.Service">

    ..then encoder works, but not the dispatcher. The name value is my service class.

    How can i get them both working?

    Wednesday, March 21, 2018 8:03 AM

All replies

  • Hi Peeter,

    >> I have a WCF Service Application, contracts are generated from WSDL (Connected Services)

    What do you mean by this? Do you mean you generate contracts from WSDL, and then create a WCF Service based on this contract?

    >> then the dispatch by body element works, but not the encoder. The name value is from WSDL, the interface WCF generated.

    Service name should be the implementation of the IService, could you share us a simple project which could reproduce your issue?

    If you manaully create a new Interface and copy the content from the generated Interface, will it work?

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, March 22, 2018 3:01 AM