简体   繁体   English

WCF安全模式TransportWithMessageCredential

[英]WCF Security Mode TransportWithMessageCredential

I've not a WCF service running as a windows service that I've converted to use the Custom UserNamePasswordValidator. 我没有作为Windows服务运行的WCF服务,我已将其转换为使用自定义UserNamePasswordValidator。

This all worked perfectly on the original setting of SecurityMode = "Transport". 在SecurityMode =“ Transport”的原始设置上,所有这些都可以完美运行。

However the only problem is that none of the faultexceptions would come back correctly. 但是,唯一的问题是没有任何错误异常会正确返回。 I guessed this was because it needs to be a security mode of TransportWithMessageCredential. 我猜这是因为它必须是TransportWithMessageCredential的安全模式。

The problem I have is when I set the security mode to be TransportWithMessageCredential the UserNamePasswordValidator validate method is now not hit. 我遇到的问题是,当我将安全模式设置为TransportWithMessageCredential时,现在没有找到UserNamePasswordValidator validate方法。

Below is my app.config. 以下是我的app.config。 Any advice would be greatly appreciated. 任何建议将不胜感激。

Thanks. 谢谢。

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

You need to include transport in the binding security section, thus: 您需要在绑定安全性部分中包括传输,因此:

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

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

相关问题 .net 核心中的 WCF (TransportWithMessageCredential) - WCF in .net core (TransportWithMessageCredential) 使用哪种WCF安全模式 - Which WCF security mode to use WCF最容易实现的安全模式 - WCF easiest security mode to implement Windows Phone错误处理:具有BasicHttpBinding和TransportWithMessageCredential的WCF - Windows Phone Error Handling: WCF with BasicHttpBinding and TransportWithMessageCredential 对于WCF服务,没有证书的TransportWithMessageCredential是否足够安全? - Is TransportWithMessageCredential without certificate secure enough for a WCF service? 在WCF服务中更改安全模式时出错 - Error when change security mode in wcf service WCF-TransportWithMessageCredential使用客户端身份验证方案“匿名”对HTTP请求进行未授权 - WCF-TransportWithMessageCredential The HTTP request is unauthorized with client authentication scheme 'Anonymous' 在同一个 WCF 绑定中同时使用 HTTP 和 HTTPS - 更改<security mode=“Transport”>至<security mode=“TransportCredentialOnly”>在代码中 - Using Both HTTP and HTTPS in same WCF Binding - Changing <security mode=“Transport”> to <security mode=“TransportCredentialOnly”> In Code 在WCF中,什么时候应该使用TransportCredentialOnly安全模式? - In WCF, when should we use TransportCredentialOnly security mode? 不选择SSL时最好的WCF安全模式是什么 - What's the best WCF security mode when SSL is not an option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM