最近我遇到了一个问题,这让我陷入了一个非常麻烦的境地。
我已经在WCF中实现了一个自定义AuthorizationManager,它首先必须按名称提取操作。WCF服务是通过REST和SOAP端点公开的,因此我必须在多个地方检查以找到我需要在身份验证过程中继续进行的信息。
一切都很好,我有大约15-20个服务运行良好,但我最近遇到了一个问题,无法使用我的正常方法来提取操作名。
拉出操作的代码如下:
public class AuthorizationManager : ServiceAuthorizationManager
{
private ServiceEndpoint _endpoint { get; set; }
public AuthorizationManager(ServiceEndpoint endpoint)
{
_endpoint = endpoint;
}
public override bool CheckAccess(OperationContext operationContext, ref Message message)
{
var buffer = message.CreateBufferedCopy(Int32.MaxValue);
message = buffer.CreateMessage();
var originalMessage = buffer.CreateMessage();
/*Step 1 - Pull Operation*/
string action = operationContext.IncomingMessageHeaders.Action ?? OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
DispatchOperation operation = operationContext.EndpointDispatcher.DispatchRuntime.Operations.FirstOrDefault(o => o.Name == action || o.Action == action);
Type hostType = operationContext.Host.Description.ServiceType;
var operationInfo = hostType.GetMethod(operation.Name);
/*Continue here using operationInfo - but operation is null*/
}
}这对于为REST和SOAP端点提取正确的操作非常有用,但是现在操作是空的。
服务定义如下:
[ServiceContract]
public interface ICollectionService
{
[OperationContract]
[WebGet]
CollectionResponse GetCollection()
}一切似乎都是标准的,我只是不明白为什么这与我的其他服务有任何不同。
发布于 2013-04-02 03:12:00
我意识到我没有仔细检查我的服务定义,它使用的是WebInvoke而不是WebGet。这个修好了。
https://stackoverflow.com/questions/15755407
复制相似问题