什么是WCF相当于HttpContext.Current.Request.RawUrl?

Gre*_*ech 34 wcf url-rewriting httpcontext operationcontext weboperationcontext

我在纯WCF上下文中运行了一些RESTful服务(即没有启用ASP.NET兼容性,因此没有HttpContext.Current可用的对象).

服务的URL在请求开始时使用IHttpModule(在此时确实具有HttpContext并使用其重写HttpContext.Current.RewritePath)来重写,以.svc从URL中删除诸如扩展之类的内容.

但是,我需要访问WCF基础结构中请求的原始URL.是否有一个相当于HttpContext.Current.Request.RawUrlOperationContextWebOperationContext类哪儿了吗?使用WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri返回重写的URL而不是原始的URL.

chr*_*ton 40

您可以通过以下方式获取当前目标端点和Uri:

OperationContext.Current.RequestContext.RequestMessage.Headers.To
Run Code Online (Sandbox Code Playgroud)

我认为是同样的事情:

OperationContext.Current.IncomingMessageHeaders.To
Run Code Online (Sandbox Code Playgroud)

这是一个System.Uri对象,我相信你可以从中得到OriginalString或者PathAndQuery,或者你想要的任何部分.