C# 具有WCF服务的消息模式密码

C# 具有WCF服务的消息模式密码,c#,asp.net,wcf,C#,Asp.net,Wcf,我正在尝试让WCF服务工作,以便它具有简单的消息用户名/密码访问权限 每当我尝试使用当前设置访问服务时,它都会显示: Metadata publishing for this service is currently disabled. 我的web.config <system.serviceModel> <bindings> <wsHttpBinding> <binding name="Binding1">

我正在尝试让WCF服务工作,以便它具有简单的消息用户名/密码访问权限

每当我尝试使用当前设置访问服务时,它都会显示:

Metadata publishing for this service is currently disabled.
我的web.config

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Binding1">
          <!-- UsernameToken over Transport Security -->
          <security mode="Message" >
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>
    <services>
      <service name="MyService" behaviorConfiguration="ServiceBehavior">
        <endpoint address="http://localhost/Service.svc" binding="wsHttpBinding" contract="IService" bindingConfiguration="Binding1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior  name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata  httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>

            <!-- Use our own custom validation -->
            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                                customUserNamePasswordValidatorType="WebApplication5.MyValidator, WebApplication5"/>
          </serviceCredentials>

        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
MyValidator.cs:

namespace WebApplication5
{
    class MyValidator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if ((userName == "shiv123") && (password == "pass123"))
            {
            }
            else
            {
                throw new FaultException("Invalid credentials");
            }
        }
    }
}

XML中的服务应该包含名称空间

尝试:

<service name="WebApplication5.MyService" ...

<service name="WebApplication5.MyService" ...