The approach will be the same, whether in the role of a web role or a working role, since both of them are essentially Windows 2008 Server (only that IIS works in the role of the Web, which also consume several ports). Whichever port you want to hang your wcf services for, just define them as input endpoints (one endpoint per port), and also determine what role this endpoint handles.
As long as you have available ports, you can have several ServiceHost. It is currently limited to 25 input endpoints and 25 full internal deployment endpoints, so this is your absolute limit. Of course, if you enable RDP, the number of available ports will drop. A: regarding protocols: if you need both http and tcp, you will need to define two endpoints, because the protocol is defined with endpoint definition.
The internal endpoint of WCF Services is pretty much identical, but you can get rid of security and go with net.tcp for a quick transfer. One difference in load balancing:
- WCF service hanging on the input endpoint will be load balanced across the entire instance of the role
- The WCF service hanging on the internal endpoint will not be load balanced.
In the latter case: let's say your web role should talk to the WCF service of the worker role role on the internal endpoint. You will need to list all the instances, get the IP + port of each of them, and then choose one randomly (or cyclic or any other method that you choose). Here is an example method that returns a random endpoint instance from a given role and a given endpoint name (code borrowed from the Michael Washam blog ):
private String GetRandomServiceIP(String roleName, String endPointName) { var endpoints = RoleEnvironment.Roles[roleName].Instances.Select(i => i.InstanceEndpoints[endPointName]).ToArray(); var r = new Random(DateTime.Now.Millisecond); int ipIndex = r.Next(endpoints.Count()); return endpoints[ipIndex].IPEndpoint.Address.ToString(); }
Regarding configuring the WCF service and its associated URI, I would strongly suggest grabbing the latest Windows Azure Training Kit and going through the Worker role , which details how to configure the ServiceHost with input endpoints and internal endpoints.
David Makogon
source share