简体   繁体   中英

WCF service throwing weird exception

after 2 days of trying to find out why my service isn't working I finally find the cause. Everytime I try to throw a new FaultException<AuthenticationException> , the server isn't actually throwing this but catching it itself.

So what is happening is that when I throw the exception the server is crashing with an unhandled System.ServiceModel.FaultException 1`.

Here is my custom exception class:

[DataContract]
public class AuthenticationException
{
    private string validationError;

    [DataMember]
    public string ValidationError
    {
        set { validationError = value; }
        get { return validationError; }
    }

    public AuthenticationException()
    {

    }

    public AuthenticationException(string valError)
    {
        validationError = valError;
    }
}

And my interface:

[ServiceContract]
public interface IAuthenticator
{
    [OperationContract]
    [FaultContract(typeof(AuthenticationException))]
    Account authenticateApplication(string userName, string Password);

What can cause this?

Edit: This is how I am throwing the exception:

            catch (Exception)
            {
                throw new FaultException<AuthenticationException>(new AuthenticationException("There was a general error during the process."), new FaultReason("Error"));
            }

Maybe your IIS server is not configured to allow passing exception to the client.

Follow the step 2 "Enable detailed errors for remote clients." of this post

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