The following goals are as follows:
Localhost: 6677/services/China
Localhost: 6677/services/USA
Localhost: 6677/services /...
All the above calls go to the service method. Because the supported countries are unknown, the method cannot be written, and the request's schame has been confirmed and cannot be modified, the following implementation is available:
Defines the service interface, including a method service.
The code is relatively simple. It only overrides the operationselector attribute and returns all requests to the method "service" (size differentiation)
Public class routebehaviorextension: behaviorextensionelement
{
Public override type behaviortype
{
Get {return typeof (routebehavior );}
}
Protected override object createbehavior ()
{
Return new routebehavior ();
}
}
Public class routebehavior: attribute, iendpointbehavior
{
Private _ operationselector;
Public routebehavior ()
{
_ Operationselector = new router ();
}
Public void addbindingparameters (serviceendpoint endpoint, system. servicemodel. channels. bindingparametercollection bindingparameters)
{
}
Public void applyclientbehavior (serviceendpoint endpoint, system. servicemodel. Dispatcher. clientruntime)
{
}
Public void applydispatchbehavior (serviceendpoint endpoint, system. servicemodel. Dispatcher. endpointdispatcher)
{
Endpointdispatcher. dispatchruntime. operationselector = _ operationselector;
}
Public void validate (serviceendpoint endpoint)
{
}
}
Internal class router: idispatchoperationselector
{
Public String selectoperation (ref message)
{
Return "service ";
}
}
Configuration:
Add routebehaviorextension and add the behavior to endpointbehaviors (note the order of behavior, which is executed from top to bottom)
Take the second parameter:
Operationcontext. Current. incomingmessageheaders. to. segments [2]