การโฮสต์บริการ WCF ที่ใช้ TCP บนพอร์ตเดียวกันกับ IIS (ผ่าน Windows Activation Service) ใน Azure WebRole

เราจะกำหนดค่า Azure Webrole ได้อย่างไรเมื่อใช้ WCF ที่ใช้ TCP บนพอร์ตเดียวกันกับ IIS

โดยทั่วไปโซลูชันภายในองค์กรจะใช้การเปิดใช้งาน WAS แต่มักจะเกี่ยวข้องกับการตั้งค่าสิทธิ์บนพอร์ต HTTP ฯลฯ ใน Windows Azure อินเทอร์เฟซนี้ไม่พร้อมใช้งาน


person halfbit    schedule 24.05.2011    source แหล่งที่มา


คำตอบ (1)


วิธีที่ดีที่สุดในการโฮสต์บริการ WCF ใน Azure WebRole คือการใช้ บริการเปิดใช้งาน Windows (WAS) ). โดยทั่วไปสิ่งนี้จำเป็นเมื่อคุณต้องการจัดเตรียมเนื้อหาเว็บ (HTTP) และบริการ WCF ที่ใช้ TCP บางอย่างบนพอร์ตเดียวกัน (80 หรือ 443)

นี่คือสคริปต์ 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())"
person halfbit    schedule 29.05.2011