I have a self-hosted WCF app using Basic HTTP Binding, no SSL, running in a console app on .NET Framework 4.0.

I have a WebGet Attribute on a method to which returns a human-readable string as a "smoke test".

If I had an ASP.NET webforms page, I would use Request.UrlReferrer or ServerVariables("HTTP_REFERER") to see if the client volunteers their redirect information.

How can I do that with WCF?

Thanks.

有帮助吗?

解决方案

If you're using BasicHttpBinding, the WebGet attribute is probably being ignored (it's used for endpoints which use the webHttpBinding and the WebHttpBehavior).

If you're using a "web" endpoint (WebHttpBinding / WebHttpBehavior), you can use the WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Referer]. If you don't have a reference to System.ServiceModel.Web.dll, you can also use the HttpRequestMessageProperty from the OperationContext:

HttpRequestMessageProperty prop;
prop = (HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
var referer = prop.Headers[HttpRequestHeader.Referer]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top