[英]Hosting TCP based WCF service on the same ports as IIS (via Windows Activation Service) in Azure WebRole
在與 IIS 相同的端口上使用基於 TCP 的 WCF 時,應該如何配置 Azure Webrole?
本地解決方案通常會使用 WAS 激活,但這通常涉及在 HTTP 端口等上設置權限。在 Windows Azure 中,此接口不可用。
在 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())"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.