0

When I set some values on an object in my client controller and then step through the debugger as far as I can, I end up here:

public class WCFServiceAuthenticateClientBehavior : IEndpointBehavior, IClientMessageInspector
{

    public WCFServiceAuthenticateClientBehavior(
        HttpRequestBase request,
        string authTokenAlias = "authToken",
        string ajaxTokenAlias = "ajaxToken")
    {

    }

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.MessageInspectors.Add(this);
    }

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        request.Headers.Add(...etc); // last call before service is here

        return null;
    }

}

If I open the Immediate Window, I can print request.toString() and see that the XML has the values that I expect. For example this value:

<d4p1:AccrualRevenueRecognition>AccrualEvenly</d4p1:AccrualRevenueRecognition>

However when the breakpoint at my Service method is hit, inspecting that object shows that AccrualRevenueRecognition does not reflect this value from the XML.

My question is: Is there a place in my service where I can debug earlier, before the method called by my client, to see if the value is lost there?

FWIW, this is only happening with enums and AccrualRevenueRecognition is an enum that looks like this:

    [DataMember]
    [Column("accrual_revenue_recognition")]
    public byte AccrualRevenueRecognitionId
    {
        get
        {
            return (byte)this.AccrualRevenueRecognition;
        }
        set
        {
            AccrualRevenueRecognition = (AccrualRevenueRecognitionChoices) value;
        }
    }

    [DataMember]
    [EnumDataType(typeof(AccrualRevenueRecognitionChoices))]
    public AccrualRevenueRecognitionChoices AccrualRevenueRecognition { get; set; }

    [DataContract]
    [Flags]
    public enum AccrualRevenueRecognitionChoices
    {
        [EnumMember]
        NotSet = 0,
        [EnumMember]
        AccrualEvenly = 1,
        [EnumMember]
        AccrualAtInvoice = 2,
        [EnumMember]
        AccrualAtPayment = 3
    }

The class containing this enum is using [DataContract, Serializable] and the method called from the client is using [VerificationSameOrigin].

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
  • Does https://stackoverflow.com/questions/2306299/how-do-you-use-xmlserialize-for-enum-typed-properties-in-c help? – mjwills Mar 16 '18 at 22:49

1 Answers1

0

I got this working and despite it being a hacky solution, I hope it helps someone else:

var success = this.Client.MyServiceCall(
    new myObject
    {
        // Because WCF obliterates the enum, casting to byte for its respective ID is needed:
        AccrualRevenueRecognitionId = (byte)viewModel.QualityOfFinancials.AccrualRevenueRecognition,
        CashRevenueRecognitionId = (byte)viewModel.QualityOfFinancials.CashRevenueRecognition
    }
);

This works because in my class, I am actually storing the int in the DB:

[DataMember]
[Column("accrual_revenue_recognition")]
public byte AccrualRevenueRecognitionId
{
    get
    {
        return (byte)this.AccrualRevenueRecognition;
    }
    set
    {
        AccrualRevenueRecognition = (AccrualRevenueRecognitionChoices) value;
    }
}
JacobIRR
  • 8,545
  • 8
  • 39
  • 68