Internal Endpoints and Windows Service
-
Dienstag, 6. März 2012 23:44
I have a Worker Role which I am hosting a WCF service on an internal endpoint using a netTcp binding. As part of the roles startup I am installing and running a Windows Service.
From within this Windows Service I would like to use the WCF service I am hosting within the role. I have tried and I have realised I cannot use the RoleEnvironment static class to get the internal endpoint address, so I pass it as an arg from within the WorkerRole when I start the Windows Service.
When I call the service from within the Windows Service the request simply timesout. If I call the service from within the WorkerRole Run() method it completes successfully.
Am I right in thinking that only components running within the RoleEnvironment have access to internal endpoints?
I would like to keep the service 'private' that is why I have made it internal so if my assumption is correct can anyone suggest a workaround.
Thanks
Alle Antworten
-
Mittwoch, 7. März 2012 06:30
You should be able to use the RoleEnvironment in your Windows Service when it is hosted on your instance. Just make sure you have the necessary references.
I already have done the same before. By default your WCF service won't be listening to the internal endpoint, since there will be no firewall rule created for the Windows Service to listen to that internal endpoint.
This is because the Windows Service process was not created by the role agent but by your startup script. Only processed created by the role agent will have the necessary firewall rules to listen to the endpoint. You have to fix this manually be adding a firewall rule with your script.
You can read the information on how the solve this here:
http://robbincremers.me/2011/11/27/communicate-by-windows-azure-instance-internal-endpoint-with-a-non-default-process/Be nice to nerds ... Chances are you'll end up working for one!
-
Mittwoch, 7. März 2012 07:22
Thanks Robbin I will give this a try. I'd also be interested to know what references you added to the Windows Service to allow it to see the RoleEnvironment, in the Windows Service code the property RoleEnvironment.IsAvailable is always FALSE.
Thanks
Richie
-
Mittwoch, 7. März 2012 07:56
I believe you only need Microsoft.WindowsAzure.ServiceRuntime. However it's difficult to tell since I added all Windows Azure references to my windows service which is being installed on a Windows Azure instance. But I can guarantee you it works, since I have a working solution where we have multiple instances which all have windows service installed on the instance, on which we are executing code through the RoleEnvironment to get endpoints.
You might have to run it in an actual Windows Azure deployment to have everything running correctly for your code in your Windows Service, since I experienced some issues with the devfabric when working with installed processes.
Be nice to nerds ... Chances are you'll end up working for one!
- Als Antwort markiert Architectural Cat Mittwoch, 7. März 2012 16:05
-
Mittwoch, 7. März 2012 16:35
Robbin,
Even after adding all the references to WindowsAzure assemblies, I still cannot access to the RoleEnvironment Instance Endpoints - RoleEnvironment.IsAvailable is always false.
Any further info you can give on this would be appreciated - adding the following to the service app.config had no affect either...
<startup useLegacyV2RuntimeActivationPolicy="True">
Thanks
Richie
-
Mittwoch, 7. März 2012 17:11
Have you tried to execute your code without checking the RoleEnvironment.IsAvailable?
If you did and you get an exception, how does the exception look like ?
Are you installing the Windows Service through a command (cmd) startup script ? Is the executioncontext on the Task set to elevated ?It must be something that makes it possible since I have a windows service reading internal endpoints from other roles in a windows service installed on the windows azure instance. The csdef for the role looks like this (I removed the unnecessary mambojambo)
<WorkerRole name="xxx" vmsize="Small" enableNativeCodeExecution="true"> <Endpoints> <InternalEndpoint name="xxx" protocol="tcp" /> </Endpoints> <Startup> <Task commandLine="xxx\xxx.cmd" executionContext="elevated" taskType="simple" /> </Startup> <Runtime executionContext="elevated" /> </WorkerRole>
My windows service configuration:
<startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> <requiredRuntime version="v4.0.20506" /> </startup>
Be nice to nerds ... Chances are you'll end up working for one!
-
Mittwoch, 7. März 2012 17:36
No exception...it returns FALSE. The Windows Service is downloaded from blob storage, installed and started within the WorkerRole Run method. My config looks exactly like you have it.

