4

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

http://server/customers/?name=约翰

重定向到

http://服务器/客户/324

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

4

1 回答 1

8

当然只需设置位置和状态码

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

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

于 2009-06-23T14:54:57.723 回答