【问题标题】:(WCF) The caller was not authenticated by the service(WCF) 调用者未经服务验证
【发布时间】:2018-08-17 15:39:56
【问题描述】:

我创建了 WCF 服务 + 客户端并将服务部署到另一台 PC。服务正在运行。但是,当我通过 Visual Studio 在调试模式下执行客户端时,我收到错误消息:调用者未通过服务进行身份验证。 PC、客户端和服务器都在同一个本地网络上。

服务器端(服务)

    <?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>

客户端配置文件:

<?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>

【问题讨论】:

    标签: c# authentication wcf-ria-services


    【解决方案1】:

    我认为问题可能是由客户端凭据引起的。 据我所知,wsHttpBinding传输安全模式默认为Message,而我们设置传输安全为message时,客户端凭证类型默认为windows。所以我们需要明确提供可以被服务器端认证的凭证。

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

    这是官方文档。 official document

    也有可能是服务端需要标识,那么客户端需要手动指定endpointidentity。这取决于您的配置和托管环境。 official document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-11
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 2010-09-22
      • 1970-01-01
      相关资源
      最近更新 更多