Host WCF service with net.tcp binding in IIS in Azure

1.6k views Asked by At

I am trying to host a WCF service with a net.tcp binding in IIS in Azure according this article http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx. But it has not any effect.

I try to do the folowing: Create CloudService Create WCF web-role In web-role project create folder Startup and place two files there: Startup.cmd

    powershell -command "set-executionpolicy Unrestricted" >> out.txt

RoleStart.ps1

    import-module WebAdministration 

    # Starting the listener service 
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpActivator'" 
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpPortSharing'" 
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()

    $WebRoleSite = (Get-WebSite "*webrole*").Name
    Get-WebApplication -Site $WebRoleSite | Foreach-Object { $site = "IIS:/Sites/$WebRoleSite" +                               $_.path; Set-ItemProperty $site -Name EnabledProtocols 'http,net.tcp'}
    New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value          @{protocol="net.tcp";bindingInformation="808:*"}

I also added net.tcp endpoint to Role properties with port 808.

First fail when i try to publish - role cyclic starts and stops. But when I disable Startup.cmd, it publishes successfully.

But even in this case, I can't resolve service reference.

What I must to do that this service will work?

2

There are 2 answers

0
Simon W On

Make sure that in your Service Definition file that your executionContext is set to 'elevated'. See this MSDN post for more details on the options available.

2
Rick Rainey On

But when I disable Startup.cmd, it publishes successfully.

I see this a lot with startup files in cloud services. If you RDP into your instance and try to run the Startup.cmd from a command prompt, then you will likely see the problem. I'm willing to bet (hence the reason I'm providing this as an answer and not a comment) is that the encoding of the Starup.cmd and/or Rolestart.ps1 are not being interpreted correctly on the machine your cloud service is deployed to. When saving these files, you need to save them using codepage 65001 (UTF 8 w/out signature) instead of the default 1252. Do this and it should resolve your problem.

I show how to do this in my blog and also provide a step-by-step solution for what you're trying to do at http://rickrainey.com/2013/08/30/hosting-a-wcf-service-in-an-azure-web-role-with-http-tcp-endpoints/. And if you're interested in securing your WCF service, you may want to check out the 2nd post at http://rickrainey.com/2013/09/18/securing-a-wcf-service-in-an-azure-web-role-with-http-tcp-endpoints-2/.