代码之家  ›  专栏  ›  技术社区  ›  Robin Sun

WCF抛出异常,服务器拒绝了客户端凭据,WCF中NetTCP的默认安全模式是什么

wcf
  •  1
  • Robin Sun  · 技术社区  · 7 年前

    我有办法解决这个问题 here

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <behaviors>
            <serviceBehaviors>
                <behavior name="BasicServiceBehavior">
                    <serviceMetadata httpGetEnabled="false"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="HCCNetTcpBinding" >
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="BasicServiceBehavior" name="HCC.SMS4.SERVICES.BASIC.MainServices">
                <endpoint address="" binding="netTcpBinding" contract="HCC.SMS4.SERVICES.BASIC.IMainServices" bindingConfiguration="HCCNetTcpBinding" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                <host>
                    <baseAddresses>
                        <add baseAddress="http://xxxx:44008/HCsmsBasicServices/"/>
                        <add baseAddress="net.tcp://xxxx:45008/HCsmsBasicServices/"/>
                    </baseAddresses>
                </host>
            </service>
        </services>
    
        <bindings>
            <netTcpBinding>
                <binding name="HCCNetTcpBinding" maxConnections="1000" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                          openTimeout="14:00:00" receiveTimeout="14:00:00" sendTimeout="14:00:00">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                </binding>
            </netTcpBinding>
        </bindings>
    
    </system.serviceModel>
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   Abraham Qian    7 年前

    <netTcpBinding>
      <binding name="netTcp">
        <security mode="Transport">
          <transport clientCredentialType="Windows" />
        </security>
      </binding>
    </netTcpBinding>
    

    因此,当您使用客户机代理类来调用服务时,可以参考以下代码。

    ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
                client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
                client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";
    var result = client.SayHello();
    

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/system-provided-bindings https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/bindings-and-security

    如果您有任何问题,请随时与我联系。

        2
  •  1
  •   TestAccount    7 年前

        3
  •  0
  •   fanuc_bob    7 年前
    推荐文章