WCF 客户端:提供的 URI 方案“http”无效;预期的“https”
本文关键字:无效 https http 方案 客户端 URI WCF | 更新日期: 2023-09-27 18:35:41
嗨,我
正在使用带有自定义用户名验证器的WCF,我正在使用Visual Studio local iis,
---------- WCF应用程序--
namespace AuthenticateWCF
{
public class CustomUserNameValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == null && password == null)
throw new ArgumentNullException();
if (!(userName == "rrr" && password == "ppp"))
throw new FaultException("incorrect password");
}
}
}
我的网络配置文件:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="AuthenticateWCF.CustomUserNameValidator, AuthenticateWCF"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SecureBasic">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="wsHttp">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
在我的测试项目中调用此服务时,
ServiceReference1.Service1Client _client = new ServiceReference1.Service1Client();
_client.ClientCredentials.UserName.UserName = "a";
_client.ClientCredentials.UserName.Password = "bb";
var result = _client.GetData(5);
客户端 Web 配置文件,这里我正在使用 TransportWithMessageCredential,来验证用户名
<binding name="BasicHttpBinding_IService1" >
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
但是当我使用它时,我收到错误
他提供的URI方案"http"无效;预期的"https"。
我知道我们可以更改安全模式,但是如果我更改此模式,则不会对用户进行身份验证。
请帮助我。
谢谢
由于您使用TransportWithMessageCredential安全模式,我假设您正在通过https使用您的服务。其次,您可以删除以下配置。
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
或将其更改为
<protocolMapping>
<add binding="basicHttpBinding" scheme="https" />
</protocolMapping>