2016-07-28 14 views
1
aufgerufen wurde

Wie finde ich den Endpunkt, der für meinen WCF-Dienst innerhalb des Autorisierungs-Managers aufgerufen wurde?C# WCF - Suchen Name des Endpunkts, der

Aktuelle Code:

public class AuthorizationManager : ServiceAuthorizationManager 
{ 
    protected override bool CheckAccessCore(OperationContext operationContext) 
    { 
     Log(operationContext.EndpointDispatcher.ContractName); 
     Log(operationContext.EndpointDispatcher.EndpointAddress); 
     Log(operationContext.EndpointDispatcher.AddressFilter); 
     //return true if the endpoint = "getDate"; 
    } 
} 

Ich möchte den Endpunkt, der genannt wurde, aber die Ergebnisse sind zur Zeit:

MYWCFSERVICE

https://myurl.co.uk/mywcfservice.svc System.ServiceModel.Dispatcher.PrefixEndpointAddressMessageFilter

Was ich brauche, ist der Teil nach der .svc zB/ https://myurl.co.uk/mywcfservice.svc/testConnection?param1=1

In diesem Szenario möchte ich "testConnection" zurückgegeben werden.

Antwort

1

Auschecken this beantworten.

public class AuthorizationManager : ServiceAuthorizationManager 
{ 
    protected override bool CheckAccessCore(OperationContext operationContext) 
    { 
     var action = operationContext.IncomingMessageHeaders.Action; 

     // Fetch the operationName based on action. 
     var operationName = action.Substring(action.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1); 

     // Remove everything after ? 
     int index = operationName.IndexOf("?"); 
     if (index > 0) 
      operationName = operationName.Substring(0, index); 

     return operationName.Equals("getDate", StringComparison.InvariantCultureIgnoreCase); 
    } 
} 
+0

Dank Kumpel, bekam die Aktion über die Operation: operationContext.RequestContext.RequestMessage.Headers.To.ToString() – markthewizard1234

+0

kühlen. Dann sollten Sie Ihre eigene Antwort veröffentlichen, um zukünftige Leser aufzuklären. :) – smoksnes

+0

Ich habe es als separate Funktion als Antwort hinzugefügt – markthewizard1234

1

Danke Smoksness! Hat mich in die richtige Richtung geschickt.

Ich habe eine Funktion gemacht, der die Aktion zurück genannt:

private String GetEndPointCalled(OperationContext operationContext) 
    { 
     string urlCalled = operationContext.RequestContext.RequestMessage.Headers.To.ToString(); 
     int startIndex = urlCalled.IndexOf(".svc/") + 5; 
     if (urlCalled.IndexOf('?') == -1) 
     { 
      return urlCalled.Substring(startIndex); 
     } 
     else 
     { 
      int endIndex = urlCalled.IndexOf('?'); 
      int length = endIndex - startIndex; 
      return urlCalled.Substring(startIndex, length); 
     } 
    } 
Verwandte Themen