How to Consume WCF Service in Service Reference if it has multiple Endpoint with name

StackOverflow https://stackoverflow.com/questions/11449995

  •  20-06-2021
  •  | 
  •  

Question

I have very specific question.. If i create one WCF Service and it has multiple endpoints with the name how can i access that using browser ? Also How can i access that in my client application via Add Service Reference ?

like my config code:

<services>
  <service name="MultipleEndpoint.SampleService" behaviorConfiguration="MultipleEndpoint.SampleService">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:55052/SampleService.svc"/>
      </baseAddresses>
    </host>
    <endpoint address="/basic" binding="basicHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="basicBinding" >
    </endpoint>
    <endpoint address="/wsHttp" binding="wsHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="wsBinding" >          
    </endpoint>
    <endpoint address="/webHttp" binding="webHttpBinding" contract="MultipleEndpoint.ISampleService" behaviorConfiguration="REST">
    </endpoint>        
  </service>
</services>

Now, when i tried to access that using

http://localhost:55052/SampleService.svc/basic or 
http://localhost:55052/SampleService.svc/wsHttp 

it gives me page/ resource not found IE Standard Error Message... Same time i like to know how would i add this type of url as a service reference in my client application ?

Was it helpful?

Solution

Those service addresses are different and they are not strictly needs to be brow-sable, means you can't browse a service for an endpoint like http://localhost:55052/SampleService.svc/basic. Those addresses are used to distinguish endpoints in communication.

If you see the wsdl of the service all the addresses of those endpoints are specified there.

If you create the proxy of the service through "Add Service Reference" all the endpoints are created in the configuration separately like..

<client>
    <endpoint address="http://localhost:54671/Service1.svc/basic"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />

    <endpoint address="http://localhost:54671/Service1.svc/ws" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
            name="WSHttpBinding_IService1">
    </endpoint>
    ...
</client>

Say if you want to talk to the service using the basic http endpoint then you can create the proxy for that by passing the corresponding endpoint configuration name in the ctor.

Ex.

// this will uses the basic http endpoint.
Service1Client client = new Service1Client("BasicHttpBinding_IService1");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top