WCF サービスで、属性 [WebAppServiceBehavior] を追加しました。この属性は、サービスのメッセージ内の一部のヘッダーの信頼性をチェックします。
これらのチェックを無視できるいくつかの特定のメソッドで他の属性を使用できる可能性はありますか?
私の問題は、サービスに 20 個のメソッドがあり、このチェックから 2 つのメソッドのみを除外したいことです。
[WebAppServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SyncService : ISyncService
{
public void DoWork() //check here
{
}
public void DoWork2()//ignore here
{
}
}
public class WebAppServiceBehavior : Attribute, IServiceBehavior
{
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
// throw new NotImplementedException();
foreach (ChannelDispatcher ch in serviceHostBase.ChannelDispatchers)
{
foreach (var endptDispatcher in ch.Endpoints)
{
endptDispatcher.DispatchRuntime.MessageInspectors.Add(new WebAppServiceMessageInspector());
}
}
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
public class WebAppServiceMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
{
var prop = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
HttpRequestMessageProperty httpProp = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
object operationName;
request.Properties.TryGetValue(WebHttpDispatchOperationSelector.HttpOperationNamePropertyName, out operationName);
if (httpProp != null && operationName != null && operationName.ToString().ToLower() == "options".ToLower())
{
return "Options";
}
/*if (ISValid Login ) //checking here For a specific header & returning error or success.
{
return instanceContext;
}
else
{
throw new FaultException("Invalid Authorization Code" + Ac.ErrorMsg);
}*/
return instanceContext;
}
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
}
}