WCF Security Error with VS 2008 Unit Test

I ran my first Visual Studio 2008 Unit Test using the WCF service and I received the following error:

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

I also get the following failed audit in the security log:

Login error: Reason: the user has not been requested access to the system type on this machine
User Name: (Internet guest account)
Domain:
Login type: 3
Login process: IIS
Authentication package:
MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
Workstation name:

I host the WCF service in IIS 6.0 on a computer running Windows XP SP3. I have both “Anonymous Access” and “Integrated Windows Authentication”, verified for the WCF service virtual directory.

Here is my configuration file for the 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>
+3
source share
4 answers

IIS WCF, "Negotiate, NTLM".

IIS:

- " " " Windows" WCF.

WCF:

- basicHttpBinding basicSettingBinding "TransportCredentialsOnly" TransportClientCredentialType "Windows"

wcf:

<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>
+5

securityMode = "" , .

+2

- Windows ( NTLM), , .

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

bindingConfiguration="myBinding"

The binding element defines modifications to the standard wsHttpBinding behavior.

Then the attribute "bindingConfiguration = myBinding" at the endpoint says that this endpoint should use the modifications we specified.

+1
source

As a side note ..... There was a GPO parameter called “NTLM Authentication Level” that controlled the authentication, which caused the unit test to throw a “Negotiate, NTLM” exception.

0
source

Source: https://habr.com/ru/post/1698425/


All Articles