netTCP绑定Soap安全协商失败

iam*_*epy 16 c# wcf exception-handling wcf-security wcf-configuration

我正在写一个WCF服务需要模拟和会话.

我尝试在我的本地计算机上调用它时没关系,但是在远程计算机上它总是失败并出现这样的错误:

安全支持提供程序接口(SSPI)身份验证失败.服务器可能未在标识为"host/hostname"的帐户中运行.如果服务器正在服务帐户(例如,网络服务)中运行,请将该帐户的ServicePrincipalName指定为服务器的EndpointAddress中的标识.如果服务器在用户帐户中运行,请将该帐户的UserPrincipalName指定为服务器的EndpointAddress中的标识.

如果我提供了upn,它会抛出一个身份失败的异常.

这是我的配置:

服务器配置(APP):

<system.serviceModel>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceAuthorization impersonateCallerForAllOperations="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="DataService.netTcpBinding">
          <readerQuotas maxArrayLength="65535" maxBytesPerRead="2147483647" maxStringContentLength="2147483647"/>
          <reliableSession enabled="true" inactivityTimeout="24:00:00" ordered="true"/>          
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="Windows" />
            <transport clientCredentialType="Windows"/>          
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="default" name="DataService.DataService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="DataService.netTcpBinding" 
          name="DataService.DataService" contract="DataService.IDataService"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://address:4504/"/>
            <add baseAddress="net.tcp://address:4503/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>     
        <bindings>
            <netTcpBinding>
                <binding name="DataService.DataService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                    maxReceivedMessageSize="65536">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="24.00:00:00"
                        enabled="true" />
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" algorithmSuite="Default" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://address:4503/" binding="netTcpBinding"
                bindingConfiguration="DataService.DataService"
                contract="ataService.IDataService" name="DataService.DataService">
              <identity>
                <dns value="DOMAIN"/>                                                  
              </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

sfu*_*qua 22

Windows服务使用用户主体名称或服务主体名称(文档)注册自己.引用该链接:" 如果服务在LocalSystem,LocalService或NetworkService帐户下运行,则默认情况下会以host /的形式生成服务主体名称(SPN),因为这些帐户可以访问计算机的SPN数据.如果服务在不同的帐户下运行,Windows Communication Foundation(WCF)将以@的形式生成UPN. "实际上,此引用与您的错误消息的说明非常相似.所以似乎......

a)如果服务在本地服务帐户或类似的标准帐户下运行,则需要调整客户端配置文件以使其具有此值,其中实际服务器的名称为"address"且端点在端口4503上运行:

<identity>
     <servicePrincipalName value="host/address:4503" />
</identity>
Run Code Online (Sandbox Code Playgroud)

b)或者,如果您在专用服务帐户下运行(我们在域名"MyDomain"上将其称为"ServiceAccount"),那么您需要

<identity>
     <userPrincipalName value="ServiceAccount@MyDomain" />
</identity>
Run Code Online (Sandbox Code Playgroud)

请注意,您可能需要在两种情况下使用完全限定的域名,包括林和树级别.对于私有LAN/WAN内的简单域,这将表示address.MyDomain.local和ServiceAccount@MyDomain.local.如果您的域位于名为MyTree的树中,那么它将是ServiceAccount@MyDomain.MyTree.local; 如果它位于名为MyForest的林中,那么它将是Serviceaccount@MyDomain.MyTree.MyForest.local(和ServicePrincipalName类似).使用Kerberos进行身份验证时,需要完全限定名称.


J S*_*J S 8

还有一个肮脏的黑客,张贴在这里,在这里,并在这里,并分析在这里.

您可以提供虚拟服务主体名称(SPN).在这种情况下,WCF不会失败,但回退到NTLM进行身份验证,而不验证主体.

所以,配置:

    <identity>
      <servicePrincipalName value="dummy" >
    </identity>
Run Code Online (Sandbox Code Playgroud)

并以编程方式

    EndpointIdentity identity = EndpointIdentity.CreateSpnIdentity("dummy");
Run Code Online (Sandbox Code Playgroud)

使用ChannelFactory:

    Uri uri = new Uri("net.tcp://<myServer>:<myPort>/myServiceAddress");
    ChannelFactory channelFactory = new ChannelFactory<IMyContract>(new NetTcpBinding());
    channelFactory.CreateChannel(new EndpointAddress(uri, identity)
Run Code Online (Sandbox Code Playgroud)

也会工作.