Question

suppose i have one wcf service with multiple endpoint having different type of binding like tcp, basichttp, wshttp etc.

<endpoint address ="" binding="wsHttpBinding"
                contract="NorthwindServices.ServiceContracts.ICustomerService"
                bindingNamespace = "http://dotnetmentors.com/services/customer" />
    <endpoint address="mex" binding="mexHttpBinding" 
                 contract="IMetadataExchange"/>

    <endpoint address ="" binding ="netNamedPipeBinding" 
                contract ="NorthwindServices.ServiceContracts.ICustomerService"
                bindingNamespace = "http://dotnetmentors.com/services/customer"  />
    <endpoint address="mex" binding="mexNamedPipeBinding" 
                 contract="IMetadataExchange"/>

so client can call my service using any endpoint having different binding. when client make call and when request will go to service end then how could i programmatically detect which binding client is using...is it tcp, basichttp, wshttp ?

so guide me with code sample which help me to detect from service that which protocol & binding client is using. thanks

Was it helpful?

Solution

Why exactly do you care about this? Your service really shouldn't care, overall, which binding the client used to get to the service if that is going to affect the service behavior (in that case, it might really make more sense to have multiple separate services).

That said, I think one possible way would be to look at the endpoint address for the service, which I think you can get using something like this (untested):

var opCtxt = OperationContext.Current;
var epAddress = opCtxt.EndpointDispatcher.EndpointAddress;
var uri = epAddress.Uri;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top