繁体   English   中英

WCF客户端:提供的URI方案“ http”无效; 预期的“ https”

[英]WCF Client : The provided URI scheme 'http' is invalid; expected 'https'

嗨,我正在使用WCF和CustomUserNameValidator,我正在使用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");


        }
    }
}

我的webconfig文件:

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

暂无
暂无

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

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