我的Web应用程序使用多个Web服务,因此我对每个Web服务都有绑定,如下所示:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICityDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
</binding>
<binding name="BasicHttpBinding_IBuildingDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
</binding>
<binding name="BasicHttpBinding_IEventDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
</binding>
...
</basicHttpBinding>
</bindings>
在我的开发环境中,我不能使用SSL(并且不需要它),但是当我去部署时,我必须使用SSL,因此我需要为每个绑定添加安全模式。我应用了以下XDT转换:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding>
<security mode="Transport" xdt:Transform="Insert">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
但是这只会将安全模式添加到第一个绑定中。但即使在阅读XDT Transform documentation和一些文章和SO问题/答案后,我也无法弄清楚如何指定一个选择所有绑定的定位器,以便将子节点添加到所有绑定中。我可以按名称指定每个绑定,但这看起来很笨拙。有什么想法吗?
答案 0 :(得分:1)
据我所知,XDT转换不支持你想要实现的目标(即在多个元素上插入新元素),这很可惜!
解决问题的一种方法可能是将安全节点添加到开发环境的所有绑定中,并将其设置为无。
然后,您可以进行一些全局替换,将所有属性更新为传输
您的web.config应该类似于
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICityDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="BasicHttpBinding_IBuildingDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="BasicHttpBinding_IEventDataService" allowCookies="true" maxBufferPoolSize="10000000" maxBufferSize="10000000" maxReceivedMessageSize="10000000">
<readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="10000000" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
你的XDT变换应该像
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- Define Global Replacements -->
<replaceAll>
<WCF_replaceBindingSecurityMode xdt:Locator="XPath(//basicHttpBinding/binding/security)" xdt:Transform="SetAttributes(mode)" mode="Transport" />
</replaceAll>
</configuration>