Search code examples
c#wcfwcf-binding

Generate client proxy from endpoint address WCF service


Is it possible for a WCF Service with two endpoints to provide a way, for the client, to generate his proxies from a specific endpoint ? I'm currently using the "Add Service Reference" feature from VS 2013 and it will obtain all classes defined by two contracts.

My two contracts define differents request/response. IServiceTCP provide admin-like methods and in IServiceHttp user-like methods.

Since I got a client who will only communicate in HTTP and he's not in the same network (making the endpoint in tcp useless), I would like to provide him a way to generate his proxies getting only classes needed from the http contract.

It seems I can provide an address to the endpoint that will be appended to the base address of the service. Since I'm hosted behind an IIS server, if I give the address "testhttp" to my endpoint, it would be resolved as "http://localhost/MyService/Service.svc/testhttp". I didn't found a way for a client to consume that address.

 <service name="Namespace.Service" behaviorConfiguration="ServiceBehaviorA">
    <endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp"  />
    <endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
  </service>

I would like to avoid creating two services to achieve this purpose.

Thanks,


Solution

  • Not sure if this can be achieved without creating two services. If you're trying to create two endpoints, this is what you should try: Give the two endpoints different service name:

    <service name="Namespace.ServiceA" behaviorConfiguration="ServiceBehaviorA">
        <endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp"  />
    </service>
    
     <service name="Namespace.ServiceB" behaviorConfiguration="ServiceBehaviorA">
        <endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
    </service>
    
    <serviceHostingEnvironment >
                <serviceActivations>
                    <add relativeAddress="ServiceA.svc" service="Namespace.ServiceA" />
                    <add relativeAddress="ServiceB.svc" service="Namespace.ServiceB" />
    </serviceActivations>/serviceHostingEnvironment>
    

    Now the two endpoints should be accessible via

    1. http://localhost/MyService/ServiceA.svc
    2. http://localhost/MyService/ServiceB.svc

    HTH.