我没有将WCF服务作为我已转换为使用自定义UserNamePasswordValidator的Windows服务运行。
这完全符合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>
答案 0 :(得分:0)
您需要在绑定安全性部分中包含传输,因此:
<binding name="TransportSecurity">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
<transport clientCredentialType="Basic" />
</security>
</binding>