WCF -- Get matched route while using the Routing Module
I开发者_运维百科 am currently creating a restful WCF project and I need to get the method that is being executed by the current request and all of the example that I find tell me to get the action name either from the Request Headers or from the Endpoint Dispatchers. However, I am not able to access these. I assume it is because I do not have any configured endpoints. I am instead using the routing module to achieve REST-ful URLs. For example, the following is defined in my Gobal.asax.cs:
RouteTable.Routes.Add(new ServiceRoute("authentication", new MavizonWebServiceHostFactory(), typeof(AuthenticationService)));
RouteTable.Routes.Add(new ServiceRoute("offers", new MavizonWebServiceHostFactory(), typeof(OfferService)));
RouteTable.Routes.Add(new ServiceRoute("settings", new MavizonWebServiceHostFactory(), typeof(SettingsService)));
RouteTable.Routes.Add(new ServiceRoute("user/cars", new MavizonWebServiceHostFactory(), typeof(CarService)));
RouteTable.Routes.Add(new ServiceRoute("user/notifications", new MavizonWebServiceHostFactory(), typeof(NotificationService)));
RouteTable.Routes.Add(new ServiceRoute("user", new MavizonWebServiceHostFactory(), typeof(UserService)));
RouteTable.Routes.Add(new ServiceRoute("version", new MavizonWebServiceHostFactory(), typeof(MetaService)));
I'm trying to get this information from the Authorization Manager so I am trying to use the OperationContext
to get this information.
Any help is greatly appreciated! Thanks! :-)
Update
I tried using the following call in the ServiceAuthorizationManager:
System.ServiceModel.OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
But nothing was returned. However, when I called this in my service method, I received the name of the service. This means that a decision has not been made at this point to which method will be called.
So, the new question is: What extensibility point should I be using to inject my custom code that depends on knowing what service method is being called, or can I invoke the route-matching service early on in the life-cycle?
The short answer was.... I gave up. WCF has a bunch of extensibility points and I just chose a point later in the WCF life-cycle where a decision had been made on the Operation Selection.
If anyone has an answer to this problem, I will gladly change my answer to yours. Thanks!
精彩评论