0
我想要做的是確保我的服務。爲此,我使用UserNameAuthentication。我做了綁定和一切,但有一些原因,當我啓動服務,我沒有得到驗證提示! 驗證方法未觸發!WCF 3.5 UserNameAuthentication不起作用?
這裏是我的webConfig
我不知道我在這裏失蹤!
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="IPhone.Service1Behavior" name="MobileService.IPhone">
<endpoint address="" binding="wsHttpBinding" contract="MobileService.IIPhone" bindingConfiguration="SafeServiceConf">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="IPhone.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MobileService.CustomValidator, MobileService" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="SafeServiceConf" maxReceivedMessageSize="65536">
<readerQuotas maxStringContentLength="65536" maxArrayLength="65536"
maxBytesPerRead="65536" />
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
這是我在IPhone.svc代碼進行驗證
我把的CustomValidator類裏面的服務!
public class CustomValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == "test" && password == "test")
return;
throw new SecurityTokenException(
"Unknown Username or Password");
}
}
任何幫助?
我只是想確保.svc文件!我可以提示客戶,但如果有人直接訪問URL,他們可以訪問服務權限? – HardCode
不,如果您使用的是UserNamePasswordValidator並且它們沒有通過正確的ClientCredintials(即用戶名和密碼),用戶將無法調用您的服務。 – ChrisNel52