c# - Visual Studio "Add Service Reference"不断将 "extendedProtectionPolicy"添加到我的配置文件

标签 c# .net wcf security iis

当我在 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/

相关文章:

c# - 使用任务并行库时线程数增长

c# - 在 N 层架构中实现数据库功能对象?

.net - NuGet 包管理器 - 找不到项目 'Default'。 - Visual Studio 2017

.net - 实现通用 Web 服务 API 的最佳方式

c# - 请求被中止 : Could not create SSL/TLS secure channel - IllegalMessage

c# - 从请求上下文中添加和检索数据

c# - 解耦命令(模式)从接收者发送类?

c# - iOS Safari 上的浏览​​器 session 之间未保存 Cookie

c# - UDPClient Async BeginReceive 很慢

c# - 为什么 Unity.Wcf 中的服务主机无法正确解析服务实例?