【发布时间】:2011-03-12 10:39:20
【问题描述】:
如何让 IIS 处理 net.tcp 连接?
【问题讨论】:
如何让 IIS 处理 net.tcp 连接?
【问题讨论】:
您需要将net.tcp 添加到您网站的启用协议中。转到 IIS 管理器,右键单击您的网站,转到“管理网站”或“管理应用程序”,然后转到“高级设置...”。在那里你会看到“启用的协议”。它可能说http。将其更改为http,net.tcp。
如果您想配置绑定,请右键单击您的网站并转到“编辑绑定...”。默认的 net.tcp 绑定是808:*。
如果您想使用 net.tcp 后面的 IIS 托管的 WCF 服务,您可能还需要检查您是否已激活所需的 Windows 功能。转到您的 Windows 功能并检查您是否已激活“Windows Communication Foundation 非 HTTP 激活”(位于“Microsoft .NET Framework 3.5.1”下)。
激活此功能后,您将获得一些额外的 Windows 服务。如果它仍然不起作用,请检查名为 'Net.Tcp Listener Adapter' 的 Windows 服务是否正在运行(应该会自动启动,但有时它不会,这是我第一次检查的地方我的net.tcp 服务停止工作)。
【讨论】:
这可能对将来的某人有所帮助。我创建了一个powershell 脚本,如果您需要automate the creation of the bindings,它将派上用场。
它会自动检查绑定是否已经存在,只有在需要时才添加。
实际脚本
Import-Module WebAdministration
$websites = Get-ChildItem 'IIS:\Sites'
$site = $websites | Where-object { $_.Name -eq 'Default Web Site' }
$netTcpExists = [bool]($site.bindings.Collection | ? { $_.bindingInformation -eq '808:*' -and $_.protocol -eq 'net.tcp' })
if (!$netTcpExists)
{
Write-Output "Net TCP binding does not exist. Creating binding now..."
# Create the binding
New-ItemProperty 'IIS:\Sites\Default Web Site' -name bindings -Value @{protocol="net.tcp";bindingInformation="808:*"}
Write-Output "Binding created"
}
else
{
Write-Output "TCP Binding already exists"
}
Write-Output "Updating enabled protocols..."
Set-ItemProperty 'IIS:\sites\Default Web Site' -name EnabledProtocols -Value "http,net.tcp"
Write-Output "Enabled protocols updated"
【讨论】:
最后一步对我有用。
【讨论】:
就我而言,我必须将 net.tcp 协议不仅添加到网站,还添加到它下面的应用程序(右键单击应用程序、高级设置、启用的协议)。
【讨论】: