1

I too am learning WCF and am new to Web Services and have a very basic question. Please indulge me! The example in the book I'm using (Learning WCF) created a ServiceHost instance specifying a base address for the service (new Uri("http://localhost:8000/HelloIndigo)), which I guess is the location of the class library implementing the service. Then a call to AddServiceEndpoint() is done with the final argument, the relative address, given as "HelloIndigoService". Is the latter nothing more than the name of the class (to be found in the library) that actually implements the service contract? (The class in question DOES bear that name.) Yet that argument is called the "address" which is mightily confusing me. Please help.

user1013210
  • 61
  • 2
  • 3

1 Answers1

3

If you're self-hosting, you can have either:

  • complete, explicit endpoint addresses in your endpoints, e.g.

    http://yourServer:8888/YourService/SomeMethodName
    

    So your endpoint defines a complete HTTP address

OR:

  • You can define a base address on the service which is the base for all endpoints of that service, and then the endpoint itself only defines the relative addresses from there on.

So in your case, the base address is http://localhost:8000/HelloIndigo - so all service endpoints will be "under" that address.

The endpoint defines a relative address of HelloIndigoService, so those two are put together and the full address in the end will be:

  http://localhost:8000/HelloIndigo/HelloIndigoService

This works for self-hosting only (when you have a host application that creates the ServiceHost class and opens it for use).

When you use IIS to host your service, then the base address is not used / not interpreted - instead, the virtual directory (in IIS) where your *.svc file exists defines your service endpoint's address.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Thank you for your answer, Marc. I guess you've partially answered what I asked. It sounds like your answer is "yes". In the book example, we're self-hosting. The class library containing the service is HelloIndigo.dll, and it contains a single class called HelloIndigoService with a single method HelloIndigo(). So I guess when it puts the full address together, the same one you listed above, it doesn't need to dig down even deeper into the class file because the class only contains a single method? Would it have been valid to append "/HelloIndigo" to specify the method name as well? – user1013210 Dec 08 '11 at 03:10