1
在與IIS相同的端口上使用基於TCP的WCF時,應如何配置Azure Webrole?在Azure Web中與IIS(通過Windows激活服務)相同的端口上託管基於TCP的WCF服務角色
內部部署解決方案通常會使用WAS激活,但這通常涉及對HTTP端口的設置權限等。在Windows Azure中,此接口不是現成的。
在與IIS相同的端口上使用基於TCP的WCF時,應如何配置Azure Webrole?在Azure Web中與IIS(通過Windows激活服務)相同的端口上託管基於TCP的WCF服務角色
內部部署解決方案通常會使用WAS激活,但這通常涉及對HTTP端口的設置權限等。在Windows Azure中,此接口不是現成的。
在Azure WebRole中託管WCF服務的最佳方式是使用Windows Activation Service (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())"