【问题标题】:WCF Client : The provided URI scheme 'http' is invalid; expected 'https'WCF 客户端:提供的 URI 方案“http”无效;预期“https”
【发布时间】:2016-02-21 04:14:23
【问题描述】:

您好,我正在使用带有 CustomUserNameValidator 的 WCF,我正在使用 Visual Studio 本地 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”。

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

请帮帮我。

谢谢

【问题讨论】:

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


    【解决方案1】:

    由于您使用 TransportWithMessageCredential 安全模式,我假设您正在通过 https 使用您的服务。 其次,您可以删除以下配置。

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

    或者改成

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

    【讨论】:

    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多