【问题标题】:WCF Security Mode TransportWithMessageCredentialWCF 安全模式 TransportWithMessageCredential
【发布时间】:2014-07-31 03:48:15
【问题描述】:

我没有作为 Windows 服务运行的 WCF 服务,我已将其转换为使用自定义 UserNamePasswordValidator。

这一切都在 SecurityMode = "Transport" 的原始设置上完美运行。

但是唯一的问题是没有一个错误异常会正确返回。 我猜这是因为它需要是 TransportWithMessageCredential 的安全模式。

我遇到的问题是,当我将安全模式设置为 TransportWithMessageCredential 时,UserNamePasswordValidator 验证方法现在没有被命中。

下面是我的 app.config。任何建议将不胜感激。

谢谢。

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
    <connectionStrings>
      <!-- hidden -->
    </connectionStrings>
    <system.serviceModel>
        <services>
            <service name="ThisApp.Global.Service.ServiceImpl" behaviorConfiguration="serviceBehaviour">
              <host>
                <baseAddresses>
                  <add baseAddress="https://testapi.ThisApp.com" />
                </baseAddresses>
              </host>
              <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="ThisApp.Global.Service.IServiceImpl" />
            </service>
        </services>

      <!--WCF Service Binding Configurations-->
      <bindings>
        <wsHttpBinding>
          <binding name="TransportSecurity">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security mode="TransportWithMessageCredential">
              <message clientCredentialType="UserName"/>
            </security>
          </binding>
        </wsHttpBinding>
      </bindings>

      <behaviors>
        <serviceBehaviors>
          <behavior name="serviceBehaviour">
            <serviceMetadata httpGetEnabled="False" httpsGetEnabled="True" />
            <serviceDebug includeExceptionDetailInFaults="True"/>
         <serviceAuthorization principalPermissionMode="Custom">
               <authorizationPolicies>
                 <add policyType="ThisApp.Global.Service.Security.AuthorizationPolicy, ThisApp.Global.Service" />
              </authorizationPolicies>
            </serviceAuthorization>
            <serviceCredentials>
              <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ThisApp.Global.Service.Security.CustomUserNameValidator, ThisApp.Global.Service" />
            </serviceCredentials>
          </behavior>
        </serviceBehaviors>
      </behaviors>

    </system.serviceModel>

    <system.diagnostics>
    <trace autoflush="true" indentsize="2">
      <listeners>
        <add name="myListener"
          type="System.Diagnostics.EventLogTraceListener"
          initializeData="ThisApp Global API" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

【问题讨论】:

    标签: c# wcf authorization transport


    【解决方案1】:

    您需要在绑定安全部分中包含传输,因此:

    <binding name="TransportSecurity">
        <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
            <transport clientCredentialType="Basic" />
        </security>
    </binding>
    

    【讨论】:

    • 感谢您的回复。不幸的是,这没有什么区别。任何访问服务的尝试都会导致:无法处理消息。这很可能是因为操作不正确,或者因为消息包含无效或过期的安全上下文令牌,或者因为绑定之间不匹配。
    • 还在上面进行了快速编辑,因为它作为 Windows 服务运行,因此是 app.config 而不是 web。干杯
    • 嗯。我正在做类似的事情。 basicHttpBinding 与使用自定义身份验证管理器的 IIS 托管服务。我需要的只是上面的配置。
    • 干杯。只能假设这与我将其作为服务运行有关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 2023-04-09
    • 2011-11-05
    相关资源
    最近更新 更多