是否可以为WCF REST服务实现HTTP 301重定向,以便以下格式的URL:

  

http:// server / customers /?name = John

重定向到

  

http:// server / customers / 324

(有关此问题的客户端案例,请参阅 WCF REST WebChannelFactory客户端是否支持使用重定向的REST服务?

有帮助吗?

解决方案

确定只需设置位置和状态代码

WebOperationContext.Current.OutgoingResponse.Location = "http://server/customers/324";
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.MovedPermanently;

我不知道WCF客户端如何处理重定向,但使用HttpWebRequest做起来相对简单。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top