Windows Vista下IIS 7发布WCF设置步骤稍微有些繁琐.
1. Control Panel -> Programs and Features -> Turn Windows features on or off -> Internet Information Services:
选中Web Management Tools -> IIS 6 Management Compatibility -> IIS Metabase and IIS 6 configuration compatibility.
World Wide Web Services -> Application Development Features下:
选中.NET Extensibility, ASP.NET, ISAPI Extensions, ISAPI Filters.
选中World Wide Web Services -> Security -> Basic Authentication.
单击OK(上面这些在默认安装IIS 7以后是不会自动安装的).
2. 因为IIS 7默认没有提供对*.svc的扩展映射, 所以需要通过WCF的ServiceModelReg.exe注册.
Run as administrator cmd
"C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe -i"
注册成功以后就可以看到IIS 7支持(查看Handler Mappings)
3. 添加IIS_IUSERS和NETWORK SERVICE的访问权限. 选中相应目录添加IIS_IUSERS, 勾选上Read&Execute, List Folder Contents, Write等.
4. Application Pool的Managed Pipeline Mode不要使用Integrated, 改为Classic. 这是我今天最郁闷的地方, 最后就是改了这个Success.
5. 如果WCF是由Silverlight调用, 需要在host添加一个名为ClientAccessPolicy.xml的文件. 用它来设置cross-domain-access的策略. 否则Silverlight应用程序调用失败.具体每个元素含义可以查阅MSDN的Network Security Access Restrictions in Silverlight 2这篇文章.
//ClientAccessPolicy.xml
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>