(WCF) The caller was not authenticated by the service

260 views Asked by At

I have created WCF service + client and deployed the service to another PC. Service is running. But when I execute client in debug mode through Visual Studio I get the error: The caller was not authenticated by the service. Both PCs, client and server are on the same local net.

Server side (service)

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <!-- This section is optional with the new configuration model  
           introduced in .NET Framework 4. -->
      <service name="Digiteq.Services.LabSat.LabSatService"
               behaviorConfiguration="LabSatServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/LabSat3/service"/>
          </baseAddresses>
        </host>
        <!-- this endpoint is exposed at the base address provided by host: http://localhost:8733/LabSat/service  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Digiteq.Services.LabSat.ILabSat" />
        <!-- the mex endpoint is exposed at http://localhost:8733/LabSat3/service/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="LabSatServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Client side config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_ILabSat" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.228.65:8000/LabSat3/service" binding="wsHttpBinding"
          bindingConfiguration="WSHttpBinding_ILabSat" contract="ILabSat"
          name="WSHttpBinding_ILabSat">
        <identity>
          <servicePrincipalName value="host/MBO-NEW" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>
1

There are 1 answers

0
Abraham Qian On

I think the problem may be caused by the client credential. As far as I know, wsHttpBinding transfer security mode is Message by default, and when we set transfer security is message, the client credential type is windows by default. So we need to explicity provide the credential which could be authenticated by server-side.

client.ClientCredentials.Windows.ClientCredential.UserName = "username";
   client.ClientCredentials.Windows.ClientCredential.Password = "password";

Here is official document. official document

It is also possible that the server side needs to be identified, then the client needs to manually specify endpointidentity. It is up to your configuration and hosting environment. official document