5

I am just trying to get to grips with using WCF, and I am wandering if someone could tell me if I have the right idea with endpoints.

I have been working through the videos on msdn, and now I am wandering about the way to configure WCF Service. The scenario is if I have multiple IServices, e.g. such that I have an IThis and IThat, and the client needs the access both (note: they will be using net.tcp),

  • IThis handles database querying and,

  • IThat handles calculations independent of the database,

I assume that I have to define separate Endpoints for IThis and IThat, that are referenced in the client separately. Or would I create an overall IThisAndThat Service that gets referenced in the client and contains the functionality for both??

Or is are the other ways for developing and handling WCF Services with multiple IServices? While I'm asking can you define base address for tcp or only http?

~Thanks all, any help or pointers would be great.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Heinrich
  • 2,144
  • 3
  • 23
  • 39

2 Answers2

4

I assume that I have to define separate Endpoints for IThis and IThat, that are referenced in the client separately. Or would I create an overall IThisAndThat Service that gets referenced in the client and contains the functionality for both??

You can do both:

  • you can create a separate service implementation class - one for IThis, another one for IThat
  • or you can create a single service implememtation class that implements both IThis and IThat

That choice is entirely up to you.

For every service implementation class that you have, you can define any number of endpoints you wish to have. So if you have an ThisService implementing IThis, you can define a HTTP and a TCP endpoint for that, and you also have a ThatService that implements IThat for which you define a TCP endpoint. That's totally up to you.

BUT: you can only define your endpoints for each service implementation class - if you have a ThisAndThatService implementing both service contracts, you cannot define 3 endpoints for IThis and two different ones for IThat - the endpoints you define are per service implementation class.

While I'm asking can you define base address for tcp or only http?

Yes, absolutely - you can define a base address for each of the various addressing schemes (http, net.tcp, net.msmq, net.pipe and so forth).

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • @marc_s surely an endpoint is per interface, not implementation class - the endpoint relies on the contract rather than implementation, afterall. Define a 'service' per implementation, but the service can have multiple endpoints each with their own (or shared) contracts...? – Kirk Broadhurst Jun 09 '11 at 00:19
  • @Kirk Broadhurst: yes - the endpoint relies on the interface - **BUT** it's defined inside the tag, which is defined once for the **service implementation class** – marc_s Jun 09 '11 at 04:57
  • @marc_s Then I don't understand "... you cannot define 3 endpoints for IThis and two different ones for IThat...". Surely you would just have 5 endpoints on the one service, 3 which implement IThis and 2 implement IThat. – Kirk Broadhurst Jun 09 '11 at 06:58
  • @Kirk Broadhurst: the endpoints from all service contracts implemented by a single service implementation class share a number of things: the service behavior configuration, the service's base addresses etc., since those are defined on a **per-service-implementation-class** level. – marc_s Jun 09 '11 at 07:19
  • @marc_s I understand, yet you wrote "if you have a ThisAndThatService implementing both service contracts, you cannot define 3 endpoints for IThis and two different ones for IThat" which I believe is misleading. You **can** define 3 endpoints for IThis and 2 different ones for IThat - they just need to be on the same service. – Kirk Broadhurst Jun 10 '11 at 01:28
  • @Kirk Broadhurst: yes, you can define three endpoints for IThis and two for IThat - but **not** with different base addresses.... – marc_s Jun 10 '11 at 04:40
1

Some basics:

Each service has one or more endpoints. The endpoints are specific to their relevant service, i.e. each endpoint can only belong to one service and cannot be shared between services.

An endpoint defines an entrypoint to the service - it includes an address, binding and contract that can be utilized by a client.

Different endpoints must have different addresses, and can have different bindings and contracts (i.e. they do not have to). Typically, different endpoints have different bindings - that is, transport protocol. They can have different contracts if particular clients are only supposed to have access to certain operations.

Finally, your service must implement all of the contracts that its various endpoints expose.

Here's a very concise and straightforward MSDN page which describes these concepts. http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/9f4391e9-8b9f-4181-a081-860d42b992a9/

There's a lot of information on WCF on the web, and there's a lot to learn. Best to look at some tutorials or guides which focus on what you are trying to do.

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169