繁体   English   中英

WCF安全模式TransportWithMessageCredential

[英]WCF Security Mode TransportWithMessageCredential

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

在SecurityMode =“ Transport”的原始设置上,所有这些都可以完美运行。

但是,唯一的问题是没有任何错误异常会正确返回。 我猜这是因为它必须是TransportWithMessageCredential的安全模式。

我遇到的问题是,当我将安全模式设置为TransportWithMessageCredential时,现在没有找到UserNamePasswordValidator validate方法。

以下是我的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>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM