2012-07-17 84 views
0

在MVC应用程序中,我有一个为我的开发环境设置的web.config,并且我有一个需要插入新的WCF服务端点的转换文件,但是它将它添加到错误的地方,所以我想我错过了一些东西。web.config变换不起作用

我削减了配置文件,只显示需要什么。

我有正常的web.config如下:

<services> 
    <!-- Report Service --> 
    <service name="Core.ReportDataHost"> 
    <endpoint name="ReportDataHost" address="..." binding="customBinding" contract="..."/> 
    </service> 

    <!-- Authentication Service --> 
    <service name="Core.AuthenticationHost"> 
    <endpoint name="AuthenticationHost" address="..." binding="customBinding" contract="..."/> 
    </service> 

</services> 

我那么有转换文件如下:

<services> 

    <service name="Core.AuthenticationHost"> 
    <endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." /> 
    </service> 

</services> 

我预计,添加新的端点在“AuthenticationHost”服务,但它将其添加到第一个服务“ReportDataHost”中。

任何想法我失踪?

回答

1

默认情况下,转换只使用标签,而不是属性,所以即使您的转换中具有name =“Core.AuthenticationHost”,它也会被忽略,并且只能使用找到的第一个Service标签匹配Service标签。

<service>标记添加一个定位器,以便它知道使用哪个标记(而不是仅使用第一个标记)。定位器是标签上的一个属性:xdt:Locator="Match(attribute1,attribute2,...)"。在这种情况下,您想匹配name属性。

你纠正变换看起来就像这样:

<services> 
    <service name="Core.AuthenticationHost" xdt:Locator="Match(name)"> 
    <endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." /> 
    </service> 
</services> 

更多信息,请访问MSDN's Transform Syntax page

+0

超级,这很有道理,明天当我回来工作时我会试试这个。谢谢。 – eyeballpaul 2012-07-18 18:52:32

+0

工作过,谢谢。 – eyeballpaul 2012-07-19 13:01:45