当我在 Visual Studio 中向服务添加服务引用时,它会不断添加此 extendedProtectionPolicy
到我的安全绑定(bind),它在我的 Win7 机器上运行良好。但是当我部署到 Server 2003 时,它会错误地指出配置文件中无法识别的元素。
删除行 <extendedProtectionPolicy policyEnforcement="Never" />
修复错误。
这是在添加服务引用(客户端)后生成的不需要的 web.config 的整个部分
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
这是我的服务正在使用的行为(iis7 主机端)
<behavior name="GetHttpsIncludeFaults">
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyCustomValidator, MyOtherAssembly"/>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
我想指出几点。这在 VS2010 和 VS2008 中都会发生。这发生在 ASP.NET-MVC 风格的消费者项目以及 Windows 服务/WPF 应用程序中。
最佳答案
据我在 Internet 和 Microsoft Connect 上找到的信息更具体地说,这是一个尚未修复的已知问题。
您可以使用 Visual Studio 2010 的 Config Transforms 功能解决此问题。Config Transforms 是一项非常有用的功能,它允许您在部署应用程序时自动更改配置文件的内容(例如连接字符串)。
不幸的是,目前只有 web.config 文件支持配置转换。 This blogpost然而,解释了如何对 app.config 文件使用配置转换。
以下转换应该可以解决您的问题:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding>
<security>
<transport>
<extendedProtectionPolicy xdt:Transform="Remove" />
</transport>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
如您所见,它删除了 <extendedProtectionPolicy/>
部署应用程序时的节点。
关于c# - Visual Studio "Add Service Reference"不断将 "extendedProtectionPolicy"添加到我的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3248284/