How to host wcf service programmatically on azure
I want to host a wcf service on Azure, but this instantiation must be dynamic, so I want to instantiate new services as needed however...
new ServiceHost(new Service(),<<What the heck is the base URI!?>>)
What's supposed to be the base Uri (Scheme, servername & port) on:
Also are these possible:
I am looking for a solution that doesn't involve ServiceBus for $$$ reasons.
The approach would be the same, whether on Web Role or Worker Role instances, since they're both essentially Windows 2008 Server (just that Web Roles have IIS running, which also consumes a few ports). Whichever port you want to hang your wcf services on, just define these as Input Endpoints (one endpoint per port), and also decide which role handles that endpoint.
As long as you have ports available, you can have multiple ServiceHosts. You're currently limited to 25 total Input Endpoints and 25 total Internal Endpoints per deployment, so this is your absolute limit. Of course, if you enable RDP, the available port count drops. Oh: regarding protocols: If you wanted both http and tcp, you'd need to define two endpoints, as the protocol is defined with the Endpoint definition.
Internal Endpoint WCF Services are pretty much identical, but you can do away with security and go with net.tcp for fast transfer. One difference in load-balancing though:
For the latter case: Let's say your Web Role needs to talk to the Worker Role's WCF service on Internal endpoint. You'd need to enumerate all instances, get the IP+port of each, then select one at random (or round-robin, or whatever method you choose). Here's a sample method that returns a random endpoint instance from a given role and given endpoint name (code borrowed from Michael Washam's 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();
}
As far as setting up the WCF service and related URI, I'd strongly suggest grabbing the latest Windows Azure Training Kit and walking through the Worker Role Communication hands-on lab, which goes into lots of detail about setting up a ServiceHost, with both Input Endpoints and Internal Endpoints.
链接地址: http://www.djcxy.com/p/59830.html上一篇: Python:结构化数据的习惯属性?