locked
Not able to run WCF service RRS feed

  • Question

  • User1778555483 posted

    I tried to implement UserNamePasswordValidator, after doing this i m getting exception, not able to figure it out. below are the details , please help.

    namespace WCFSecurity
    {
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            string GetData();
        }
    }
    
    using System.IdentityModel.Selectors;
    using System.IdentityModel.Tokens;
    namespace WCFSecurity
    {
        public class Service1 : IService1
        {
            public string GetData()
            {
                return string.Format("Hello World");
            }
        }
        public class CustomValidator : UserNamePasswordValidator
    	{
    	        public override void Validate(string userName, string password)
    	        {
    	            if (userName == "test" && password == "test")
    	                return;
    	            throw new SecurityTokenException(
    	                "Unknown Username or Password");
    	        }
    	}
    }
    
    <system.serviceModel>
        <services>
          <service name="WCFSecurity.Service1" behaviorConfiguration="myBehaviour">
            <endpoint address="" binding="wsHttpBinding" contract="WCFSecurity.Service1" bindingConfiguration="SafeServiceConf"/>
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
          </service>
        </services>
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="myBehaviour">
    					<serviceMetadata httpGetEnabled="true"/>
    					<serviceDebug includeExceptionDetailInFaults="false"/>
              <serviceCredentials>
                <userNameAuthentication
                     userNamePasswordValidationMode="Custom"
                     customUserNamePasswordValidatorType="WCFSecurity.CustomValidator,WCFSecurity"/>
              </serviceCredentials>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        <bindings>
          <wsHttpBinding>
            <binding name="SafeServiceConf" maxReceivedMessageSize="65536">
              <readerQuotas maxStringContentLength="65536" maxArrayLength="65536"
              maxBytesPerRead="65536" />
              <security mode="TransportWithMessageCredential">
                <message clientCredentialType="UserName" />
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
      </system.serviceModel>
    

    Getting this Exception

    Server Error in '/WCFSecurity' Application.


    Could not load type 'WCFSecurity.CustomValidator' from assembly 'WCFSecurity'


    Saturday, January 26, 2013 1:22 AM

Answers

  • User-1000095884 posted

    Hi,

    Could not load type 'WCFSecurity.CustomValidator' from assembly 'WCFSecurity'

    The issue may located at "customUserNamePasswordValidatorType="WCFSecurity.CustomValidator,WCFSecurity" ", please check the location of the class, the first part is the class name fully qualified by the namespace, the second is the assembly the class is in.

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 28, 2013 2:15 AM