简体   繁体   中英

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

Hi I am using WCF with CustomUserNameValidator, i am using visual studio local iis,

---------- WCF application--

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");


        }
    }
}

my webconfig file:

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

when calling this service in my test project,

ServiceReference1.Service1Client _client = new ServiceReference1.Service1Client();
_client.ClientCredentials.UserName.UserName = "a";
_client.ClientCredentials.UserName.Password = "bb";
var result = _client.GetData(5);

client web config file, here i am using TransportWithMessageCredential, to validate username

<binding name="BasicHttpBinding_IService1" >
    <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
    </security>
</binding>

but when i use this i am getting error

he provided URI scheme 'http' is invalid; expected 'https'.

I know we can change security mode, but if i change this will not authenticate user.

Please help me.

Thanks

Since you using TransportWithMessageCredential security mode I assume your are consuming your service over https. Secondly you either remove following configuration.

<protocolMapping>
    <add binding="basicHttpBinding" scheme="http" />
</protocolMapping>

Or change it to

<protocolMapping>
    <add binding="basicHttpBinding" scheme="https" />
</protocolMapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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