使用“?wsdl”从 REST WCF 服务中删除 .svc和“/help”仍然启用
之前的 SO 问题/答案都没有引导我找到完整的 REST / WCF 解决方案,从服务的各个方面删除 SVC 扩展。
具体来说,我指的是 servicename/help
和 servicename/wsdl
...但我知道这是可能的。 这是一个能够从 /help 链接删除 WCF 扩展的工作示例。此外,他还使得直接使用扩展名调用 .svc 变得不可能。 WSDL 似乎不存在(尽管我更愿意保留它)
如何使我的 WCF REST 应用程序的行为更像该链接?
下面是 IIS URL 重写,它帮助我实现了这一点。这看起来有点做作,因为如果我没有第一次(两次)重写,那么网络服务就会随机崩溃。
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
<rules>
<rule name="test1.svc" stopProcessing="true" >
<match url="^test1.svc(.*)$"/>
</rule>
<rule name="test1" stopProcessing="true" >
<match url="^test1(.*)$"/>
<action type="Rewrite" url="/test1.svc{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
None of the prior SO questions/answers lead me to a complete REST / WCF solution that removes the SVC extension from all aspects of the service.
Specifically I'm referring to servicename/help
and servicename/wsdl
... but I know it's possible. Here is a working example of someone who is able to remove the WCF extension from the /help link. In addition he made it impossible to call the .svc directly with the extension. It appears that the WSDL is non existent (though I'd prefer to keep this)
How do I make my WCF REST application act more like that link?
Here is the IIS URL Rewrite that gets me part way there. It seems kind of hokey because if I don't have the first (of two) rewrites then the web service randomly gets borked.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
<rules>
<rule name="test1.svc" stopProcessing="true" >
<match url="^test1.svc(.*)$"/>
</rule>
<rule name="test1" stopProcessing="true" >
<match url="^test1(.*)$"/>
<action type="Rewrite" url="/test1.svc{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您发布的链接,我假设您正在使用 .Net Framework 4。如果是这种情况,您不需要使用 .svc 文件,因为它现在与 ASP.NET 路由。因此,您可以使用新的 ServiceRoute 类将服务 URL 添加到 ASP.NET 路由表< /a>.有关详细信息,请参阅以下文章。
I'm assuming that you are using .Net Framework 4, based on the link you posted. If this is the case, you don't need to use .svc files, because it now integrates with ASP.NET routing. Therefore, you can use the new ServiceRoute class to add your service URLs to the ASP.NET Route table. For more information see the following article.
WCF 4 还允许您使用无文件激活和 Windows 激活服务提供别名寻址。 (曾是)
WCF 4 also allows you to provide alias addressing using fileless activation and Windows Activation Services. (WAS)