我有一个公开 2 个端点的服务,我想仅将消息格式应用于其中一个端点。
为此,我希望捕获端点名称,以便仅将 MessageFormatter 应用于此特定端点。
这是我的操作行为属性的代码:
public class JsonRpcMessageValidation : Attribute, IOperationBehavior
{
#region Properties
public Type serializeType { get; set; }
public Type deserializeType { get; set; }
#endregion
#region Constructors
/// <summary>
///
/// </summary>
/// <param name="serializeType">Serialize Type</param>
/// <param name="deserializeType">Deserialize Type</param>
public JsonRpcMessageValidation(Type serializeType, Type deserializeType)
{
this.serializeType = serializeType;
this.deserializeType = deserializeType;
}
#endregion
#region Methods
public void AddBindingParameters(OperationDescription operationDescription, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation)
{
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation)
{
JsonRpcRequestMessageInspector jrrmInspector = new JsonRpcRequestMessageInspector();
dispatchOperation.ParameterInspectors.Add(jrrmInspector);
JsonRpcMessageFormatter jrmFormatter = new JsonRpcMessageFormatter(serializeType, deserializeType);
dispatchOperation.Formatter = jrmFormatter;
}
public void Validate(OperationDescription operationDescription)
{
}
#endregion
}
我用这个属性装饰了接口中的方法,我需要类型信息以便对传入和传出的消息执行序列化和反序列化。
有谁知道如何在代码中获取当前端点信息?
谢谢