문제

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