i'm having trouble implementing url redirection using message inspectors wcf rest service. idea implement afterreceiverequest change incoming request nothing, , in beforesendreply, make call uri provides actual service. can think of scenario not want break clients, continue use old uris invocations, internally redirect them different uri.
for example, service contract looks like:
[servicecontract] public interface iservice1 { [operationcontract] [webget(uritemplate = "person/{person}")] string greetme(string person); [operationcontract] [webget(uritemplate = "donothing")] string donothing(); }
and implementation:
public class service1 : iservice1 { public string greetme(string person) { return string.format("hi {0}", person); } public string donothing() { return string.empty; } }
then i'm adding messageinspector endpoint behavior. afterreceiverequest of inspector this:
public object afterreceiverequest(ref message request, iclientchannel channel, instancecontext instancecontext) { operationcontext operationcontext = operationcontext.current; if (weboperationcontext.current != null && weboperationcontext.current.incomingrequest.uritemplatematch != null) { uribuilder baseuribuilder = new uribuilder(weboperationcontext.current.incomingrequest.uritemplatematch.baseuri); uribuilder requesturibuilder = new uribuilder(weboperationcontext.current.incomingrequest.uritemplatematch.requesturi); operationcontext.current.incomingmessageproperties["microsoftdataservicesrooturi"] = baseuribuilder.uri.tostring(); operationcontext.current.incomingmessageproperties["microsoftdataservicesrequesturi"] = baseuribuilder.uri.tostring() + "donothing"; operationcontext.current.incomingmessageheaders.to = new uri(baseuribuilder.uri.tostring() + "donothing"); operationcontext.incomingmessageproperties["via"] = new uri(baseuribuilder.uri.tostring() + "donothing"); request.headers.to = new uri(baseuribuilder.uri.tostring() + "donothing"); } return null; }
basically, want change incoming requests go donothing() operation. however, when run this, still see request makes greetme method. attached debugger , can see code in afterreceiverequest getting executed, i'm not sure why uri redirection not happen.
any ideas?