在 Azure WebRole 中与 IIS 相同的端口上托管基于 TCP 的 WCF 服务(通过 Windows 激活服务)

发布于 2024-11-09 04:04:50 字数 134 浏览 3 评论 0原文

在与 IIS 相同的端口上使用基于 TCP 的 WCF 时,应如何配置 Azure Webrole?

本地解决方案通常会使用 WAS 激活,但这通常涉及在 HTTP 端口等上设置权限。在 Windows Azure 中,此接口不容易使用。

How should one configure an Azure Webrole when using a TCP-based WCF on the same ports as IIS?

An on-premise solution would typically use WAS activation, however this usually involved setting permissions on the HTTP ports etc. In Windows Azure this interface isn't readily available.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2024-11-16 04:04:50

在 Azure WebRole 中托管 WCF 服务的最佳方法是使用 Windows 激活服务 (WAS )。通常,当您想要在同一端口(80 或 443)上提供 Web 内容 (HTTP) 和某些基于 TCP 的 WCF 服务时,需要这样做。

下面是一个 PowerShell 脚本,它将启用 TCPPortSharing 服务并适当配置 IIS。虽然这适用于 Azure,但只需稍加修改,您也可以将其用于本地 Windows 2008 R2 服务器。

#adding this to be sure that IISConfigurator has a chance complete

Add-Content -path .\trace.txt "Starting...$([Datetime]::Now.ToString())" 

Start-Sleep -s 300

Add-Content -path .\trace.txt "Adding Microsoft.WindowsAzure.ServiceRuntime..."
Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
while (!$?)
{
    Add-Content -path .\trace.txt "Failed to add Microsoft.WindowsAzure.ServiceRuntime, retrying after five seconds..."
    sleep 5

    Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
}

Add-Content -path .\trace.txt "...done adding Microsoft.WindowsAzure.ServiceRuntime $([Datetime]::Now.ToString())"

#Start the Net.TCP Port Sharing and Net.Tcp Listener Adaptor services.. (TODO:Not sure if we need to set this to auto)

Add-Content -path .\trace.txt "Setting NetTcpPortSharing & NetTcpActivator service startup to auto... $([Datetime]::Now.ToString())"

Set-Service NetTcpPortSharing -StartupType Automatic
Set-Service NetTcpActivator -StartupType Automatic

Add-Content -path .\trace.txt "...done Setting NetTcpPortSharing & NetTcpActivator service startup to auto ... $([Datetime]::Now.ToString())"

Add-Content -path .\trace.txt "Starting NetTcpPortSharing & NetTcpActivator services ... $([Datetime]::Now.ToString())"

Start-Service -name NetTcpPortSharing
Start-Service -name NetTcpActivator

Add-Content -path .\trace.txt "... done Starting NetTcpPortSharing & NetTcpActivator services $([Datetime]::Now.ToString())"

#Get the Role Instance Id

Add-Content -path .\trace.txt "Getting the RoleInstance ID... $([Datetime]::Now.ToString())"

$roleInstance = Get-RoleInstance -current
$roleInstanceId = $roleInstance.Id

$siteName = '_Web'  #This is the site name from the <Site> tag in ServiceDefinition.csdef

Add-Content -path .\trace.txt "Instance ID : $roleInstanceId"

Add-Content -path .\trace.txt "... done Getting the RoleInstance ID $([Datetime]::Now.ToString())"

#Create the bindingCmd

#Add-Content -path .\trace.txt "Building commands ..."

#$addBindingCmd =  "set site `"" + $roleInstanceId + "_" + $siteName + "`" -+bindings.[protocol='net.tcp',bindingInformation='808:*']"
#$enableNetTcpCmd =  "set app `"" + $roleInstanceId + "_" + $siteName + "`" /enabledProtocols:http,net.tcp"

Add-Content -path .\trace.txt -value $addBindingCmd
Add-Content -path .\trace.txt -value $enableNetTcpCmd
Add-Content -path .\trace.txt -value "...done Building commands"

set-alias appCmd $env:windir\system32\inetsrv\appcmd.exe

Add-Content -path .\trace.txt -value "Adding Net.Tcp binding... $([Datetime]::Now.ToString())"

#add the binding..
#appCmd $addBindingCmd 

appCmd set site `"$roleInstanceId$siteName`" /debug -+"bindings.[protocol='net.tcp',bindingInformation='808:*']" >>trace.txt

Add-Content -path .\trace.txt -value "done Adding Net.Tcp binding"

Add-Content -path .\trace.txt -value "Enable Net.Tcp... $([Datetime]::Now.ToString())"
#appCmd $enableNetTcpCmd
appCmd set app "$roleInstanceId$siteName/" /debug /enabledProtocols:"http,net.tcp" >> trace.txt
Add-Content -path .\trace.txt -value "done Enable Net.Tcp"

Add-Content -path .\trace.txt -value "End $([Datetime]::Now.ToString())"

The best way to host a WCF service in an Azure WebRole is using Windows Activation Service (WAS). Typically this is needed when you want to provide web content (HTTP) and some TCP-based WCF service on the same ports (80 or 443).

Here is a PowerShell script that will enable the TCPPortSharing service, and configure IIS appropriately. Although this works for Azure, with slight modification you can use this for an on-premise Windows 2008 R2 server as well.

#adding this to be sure that IISConfigurator has a chance complete

Add-Content -path .\trace.txt "Starting...$([Datetime]::Now.ToString())" 

Start-Sleep -s 300

Add-Content -path .\trace.txt "Adding Microsoft.WindowsAzure.ServiceRuntime..."
Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
while (!$?)
{
    Add-Content -path .\trace.txt "Failed to add Microsoft.WindowsAzure.ServiceRuntime, retrying after five seconds..."
    sleep 5

    Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime
}

Add-Content -path .\trace.txt "...done adding Microsoft.WindowsAzure.ServiceRuntime $([Datetime]::Now.ToString())"

#Start the Net.TCP Port Sharing and Net.Tcp Listener Adaptor services.. (TODO:Not sure if we need to set this to auto)

Add-Content -path .\trace.txt "Setting NetTcpPortSharing & NetTcpActivator service startup to auto... $([Datetime]::Now.ToString())"

Set-Service NetTcpPortSharing -StartupType Automatic
Set-Service NetTcpActivator -StartupType Automatic

Add-Content -path .\trace.txt "...done Setting NetTcpPortSharing & NetTcpActivator service startup to auto ... $([Datetime]::Now.ToString())"

Add-Content -path .\trace.txt "Starting NetTcpPortSharing & NetTcpActivator services ... $([Datetime]::Now.ToString())"

Start-Service -name NetTcpPortSharing
Start-Service -name NetTcpActivator

Add-Content -path .\trace.txt "... done Starting NetTcpPortSharing & NetTcpActivator services $([Datetime]::Now.ToString())"

#Get the Role Instance Id

Add-Content -path .\trace.txt "Getting the RoleInstance ID... $([Datetime]::Now.ToString())"

$roleInstance = Get-RoleInstance -current
$roleInstanceId = $roleInstance.Id

$siteName = '_Web'  #This is the site name from the <Site> tag in ServiceDefinition.csdef

Add-Content -path .\trace.txt "Instance ID : $roleInstanceId"

Add-Content -path .\trace.txt "... done Getting the RoleInstance ID $([Datetime]::Now.ToString())"

#Create the bindingCmd

#Add-Content -path .\trace.txt "Building commands ..."

#$addBindingCmd =  "set site `"" + $roleInstanceId + "_" + $siteName + "`" -+bindings.[protocol='net.tcp',bindingInformation='808:*']"
#$enableNetTcpCmd =  "set app `"" + $roleInstanceId + "_" + $siteName + "`" /enabledProtocols:http,net.tcp"

Add-Content -path .\trace.txt -value $addBindingCmd
Add-Content -path .\trace.txt -value $enableNetTcpCmd
Add-Content -path .\trace.txt -value "...done Building commands"

set-alias appCmd $env:windir\system32\inetsrv\appcmd.exe

Add-Content -path .\trace.txt -value "Adding Net.Tcp binding... $([Datetime]::Now.ToString())"

#add the binding..
#appCmd $addBindingCmd 

appCmd set site `"$roleInstanceId$siteName`" /debug -+"bindings.[protocol='net.tcp',bindingInformation='808:*']" >>trace.txt

Add-Content -path .\trace.txt -value "done Adding Net.Tcp binding"

Add-Content -path .\trace.txt -value "Enable Net.Tcp... $([Datetime]::Now.ToString())"
#appCmd $enableNetTcpCmd
appCmd set app "$roleInstanceId$siteName/" /debug /enabledProtocols:"http,net.tcp" >> trace.txt
Add-Content -path .\trace.txt -value "done Enable Net.Tcp"

Add-Content -path .\trace.txt -value "End $([Datetime]::Now.ToString())"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文