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

时间:2016-02-21 04:14:23

标签: c# asp.net asp.net-mvc wcf forms-authentication

您好我正在使用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计划&#39; http&#39;是无效的;预期&#39; https&#39;。

我知道我们可以更改安全模式,但如果我更改了这将不会对用户进行身份验证。

请帮帮我。

由于

0 个答案:

没有答案