【发布时间】:2022-11-19 13:59:50
【问题描述】:
我的 WCF 有以下两条规则:
<system.webServer>
<rewrite>
<rules>
<!-- Rewrite requests to /MyService to /MyService.svc -->
<rule name="MyService" stopProcessing="false">
<match url="MyService/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/MyService.svc/{R:1}" />
</rule>
<!-- Remove path /MoreServices from url -->
<rule name="example" stopProcessing="true">
<match url=".*(MoreServices)(.+)" ignoreCase="true" />
<action type="Rewrite" url="{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
第一条规则:
<!-- Rewrite requests to /MyService to /MyService.svc -->
<rule name="MyService" stopProcessing="false">
<match url="MyService/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/MyService.svc/{R:1}" />
</rule>
将在没有 svc 扩展的情况下发送的调用重写到 svc 服务。
第二条规则:
<!-- Remove path /MoreServices from url -->
<rule name="example" stopProcessing="true">
<match url=".*(MoreServices)(.+)" ignoreCase="true" />
<action type="Rewrite" url="{R:2}" />
</rule>
删除额外的路径并定向到正确的服务。
一切正常,但是,我将发布到的站点不允许在 web.config 中使用 <rule> 标记。我的问题是,如何修改我的 WCF 以编程方式完成上述两条规则。基本上在 C# 中复制上述两项的逻辑作为 WCF 服务的一部分。谢谢你。
【问题讨论】:
标签: c# asp.net wcf wcf-binding