WCF:使用OperationContext区分REST和SOAP请求

uri*_*rig 7 rest wcf soap operationcontext

在WCF安全性中,给定当前的OperationContext,确定请求是SOAP请求还是REST请求的最佳方法是什么?

mar*_*c_s 10

您可以查看ChannelDispatcher上的绑定名称:

string bindingName = OperationContext.Current
                        .EndpointDispatcher.ChannelDispatcher.BindingName;
Run Code Online (Sandbox Code Playgroud)

对于REST,它将是webHttpBinding- 其他任何东西都是SOAP.