Search code examples
c#wcfwcf-bindingwcf-endpoint

Restrict client application to consume wcf service on only one endpoint


I have developed a wcf service having two contracts Contract1 and Contract2 exposed on two different endpoints. When i am going to add reference to my client application it allows me to consume both contracts.

How i restrict client application to consume only one contract?

here is my web.config's code

<system.serviceModel>
    <services>
        <service behaviorConfiguration="MyWCFService.Service1Behavior"
         name="MyWCFService.Service1">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:1010/Service1.svc"/>
                </baseAddresses>
            </host>

            <endpoint address="/MyService1" binding="wsHttpBinding" contract="MyWCFService.IService1" />                
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <endpoint address="/MyService2" binding="wsHttpBinding" contract="MyWCFService.IService2" />

        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyWCFService.Service1Behavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Thanks in advance.


Solution

  • why not break single webservice endpoint with 2 contracts into two webservice endpoints on different addresses and 1 contract per each and use only one in your client application.

    Its unclear why your design requires 2 contracts on 1 endpoint , only allowing client to use 1 contract.

    Or add some security, maybe some fairly basic stuff like add password field to method signatures in contract you want to restrain access to.