我有一个在地址上使用 wsHttpBinding 托管的服务(主机基地址为 http://localhost/MyService)。
在我的合同(IMyService
)中,我有:
[OperationContract]
[WebInvoke(
Method = "GET",
UriTemplate = "/")]
Stream GetRootPage();
如果我运行我的服务并浏览到 http://localhost /MyService/,它工作正常。如果我浏览到 http://localhost/MyService,我会看到一个默认的 WCF 页面,指示元数据发布服务是未启用此服务。
我尝试了 UriTemplate 的各种组合:
- UriTemplate = ""
- UriTemplate = "/"
- UriTemplate = "*"
与服务基地址结合:
所有这些都会产生相同的行为。在之前的某个时刻,我可以发誓这是有效的,尽管我认为我可能一直在 UriTemplate 中使用子路径。我知道,如果我的 UriTemplate 为“/abc/123/”,我可以浏览到 /abc/123(不带尾部斜杠),因为 WCF 实际上会自动发出 HTTP 307 重定向。
我正在使用.NET 4.0。
I have a service hosted using wsHttpBinding on an address (the host base address is http://localhost/MyService).
In my contract (IMyService
), I have:
[OperationContract]
[WebInvoke(
Method = "GET",
UriTemplate = "/")]
Stream GetRootPage();
If I run my service and browse to http://localhost/MyService/, it works fine. If I browse to http://localhost/MyService, I am greeted with a default WCF page indicating that the metadata publishing service is not enabled for this service.
I have tried various combinations of UriTemplate:
- UriTemplate = ""
- UriTemplate = "/"
- UriTemplate = "*"
In combination with the service base address:
All of them yield the same behavior. At some point previously, I could have sworn this was working, though I think I may have been using a subpath in the UriTemplate. I know that if I have a UriTemplate of "/abc/123/", I can browse to /abc/123 (without the trailing slash) because WCF actually issues an HTTP 307 redirect automatically.
I am using .NET 4.0.
发布评论
评论(2)
我想出了如何做到这一点:
确保禁用默认 WSDL 生成(或至少不使用默认 URL):
确保禁用帮助 URL:
I figured out how to do this:
Ensure that the default WSDL generation is disabled (or at least not using the default URL):
Ensure that the help URL is disabled:
我认为您的问题已经在以下位置得到解答:简单WCF Rest 4.0 中的 URL 路由不带尾部斜杠。
你能证实一下吗?
I think your question is already answered in: Simple URL routes in WCF Rest 4.0 without trailing slash.
Can you verify that?