我有一个获取 GET 请求的 REST 服务,我希望它能够重定向到三个 url 之一,而不必发送http 302
错误和新的 url。
[OperationContract(Name = "MyService")]
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/myservice/{option}")]
public System.IO.Stream MyService(String option)
这就是我定义它的方式,但是当我查看时,WebOperationContext.Current.OutgoingResponse
我没有重定向方法。
有没有办法自动做到这一点?我希望这样做的原因是该 Web 服务可能被程序调用,并且在程序上不必捕获 302 错误然后手动执行重定向会更简单。
看来正确的方法是遵循这个: http ://christopherdeweese.com/blog2/post/redirecting-from-a-wcf-rest-service
并这样做:
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Redirect;
WebOperationContext.Current.OutgoingResponse.Location = "/someOtherPage.aspx";
return null;
我只是希望找到另一个解决方案。