2008-10-17 9 views
3

je courais mon premier Visual Studio 2008 Test Unit avec un service WCF et j'ai reçu l'erreur suivante:WCF Erreur de sécurité avec VS 2008 Test Unit

Test method UnitTest.ServiceUnitTest.TestMyService threw exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized..

Je reçois également les éléments suivants audit a échoué dans la sécurité log:

Logon Failure: Reason: The user has not been granted the requested logon type at this machine
User Name: (Internet Guest Account)
Domain:
Logon Type: 3
Logon Process: IIS
Authentication Package:
MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
Workstation Name:

J'héberge le service WCF dans IIS 6.0 sur un ordinateur Windows XP SP3. J'ai à la fois les "Anonymous Access" et "Authentification Windows intégrée" vérifiés pour le répertoire virtuel du service WCF.

Voici mon fichier de configuration pour le service:

<system.serviceModel> 
    <services> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="MyBinding"> 
       <security mode="None" /> 
      </binding> 
      </basicHttpBinding> 
      <customBinding> 
       <binding name="MyBinding"> 
       <transactionFlow /> 
        <textMessageEncoding /> 
        <httpsTransport authenticationScheme="Ntlm"/> 
       </binding> 
      </customBinding> 
      <wsHttpBinding> 
       <binding name="MyBinding"> 
        <security mode="None" /> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <service 
      behaviorConfiguration="Service1Behavior" 
      name="Service1" 
     > 
      <endpoint 
       address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="MyBinding" 
       contract="IService1" 
      > 
       <identity> 
        <dns value="localhost" /> 
        </identity> 
      </endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="Service1Behavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

Répondre

5

je devais changer les configurations IIS et de services WCF suivants pour franchir l'exception "Negotiate, NTLM"

IIS configurations:.

-- Unchecked "Anonymous Access" checkbox and check the "Integrated Windows authentication" checkbox in the directory security setting for the WCF Service virtual directory.

WCF Services:

-- implemented basicHttpBinding and configured the basicSettingBinding security setting to "TransportCredentialsOnly" mode and TransportClientCredentialType to "Windows"

Voici ma configuration de service WCF mise à jour:

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="windowsBasicHttpBinding"> 
       <security mode="TransportCredentialOnly"> 
        <transport clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service  
     behaviorConfiguration="CityOfMesa.ApprovalRouting.WCFService.RoutingServiceBehavior" 
      name="CityOfMesa.ApprovalRouting.WCFService.RoutingService" 
     > 
      <endpoint 
       binding="basicHttpBinding" bindingConfiguration="windowsBasicHttpBinding" 
       name="basicEndPoint"  
       contract="CityOfMesa.ApprovalRouting.WCFService.IRoutingService" 
      /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior 
       name="CityOfMesa.ApprovalRouting.WCFService.RoutingServiceBehavior" 
      > 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 
+0

@alhambraeidos - Je ne suis pas sûr de ce que vous essayez de demander à propos du 'RoutingServiceBehavior' –

1

L'authentification par défaut est Windows (ou NTLM) vous aurez donc besoin de préciser que vous ne voulez pas l'authentification dans votre fichier de configuration.

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="myBinding"> 
     <security mode="None" /> 
     </binding> 
    </bindings> 
</system.serviceModel> 

également ajouter cet attribut au point d'extrémité

bindingConfiguration="myBinding" 

L'élément de liaison spécifie les modifications du comportement standard du wsHttpBinding.

Alors le « bindingConfiguration = » Mybinding » attribut sur le point de terminaison dit que ce critère devrait utiliser les modifications que nous avons spécifiées.

+0

Ne fonctionne pas. J'ai reçu le même message d'erreur. –

+0

Mis à jour en mode de sécurité Aucun – Karg

+0

Cela ne fonctionne toujours pas ... J'ai même ajouté l'attribut bindingName au noeud de service. –

2

Lorsque vous avez SECURITYMODE = « Aucun » dans votre reliure, vous devez désactiver l'authentification intégrée.

+0

J'ai essayé et reçu l'erreur suivante lorsque j'ai essayé de mettre à jour la référence de service dans le projet de test: Les métadonnées contiennent une référence qui ne peut pas être résolue ''. La requête HTTP n'est pas autorisée avec le schéma d'authentification client 'Anonyme'. L'en-tête d'authenication reçu du serveur –

+0

Cont .... était ''. Le serveur distant a renvoyé une erreur: (401) Non autorisé. –

+0

Pouvez-vous naviguer vers le WSDL? Si vous désactivez l'authentification intégrée et activez l'authentification anonyme et que SecurityMode = "None" sur le client et le serveur, cela devrait fonctionner. – jezell

0

Comme une note de côté ..... Il y avait un paramètre GPO "authentification NTLM niveau" qui était contrôle Authentification qui provoquait le test unitaire pour générer l'exception "Négocier, NTLM".

Questions connexes