1

If I have a WCF service project where one of the classes used in the service looks like this:

public class Test {
    public int Num { get; set; }
    public bool IsHigh => Num > 7;
}

Then the expression bodied member seems to go missing in the generated wsdl/reference:

<xs:extension base="tns:Test">
    <xs:sequence>
        <xs:element minOccurs="0" name="Num" type="xs:int"/>
        // <--- Missing 'IsHigh'-member
    </xs:sequence>
</xs:extension>

Is there any way to make 'IsHigh' to be included (and subsequently be used in the calling client)?

(Or is it possible I have made an error somewhere else in my implementation, and that the expression bodied member should really be found in the reference?)

Grateful for any help!

Mystogan
  • 547
  • 4
  • 21
  • 1
    what will happen with `public bool IsHigh { get => Num > 7; set { } }`? To be clear: I think it is excluded because you property is readonly. – vasily.sib Jul 05 '19 at 08:13
  • That did the trick, thank you for the help! – Mystogan Jul 05 '19 at 08:26
  • still I don't know why do you need a _"readonly-by-nature"_ property in your `wsdl`? :) – vasily.sib Jul 05 '19 at 08:28
  • The above is a simplified case, the real 'Num > 7' is more complex, and I do want the resulting information available to the client, while also not exposing the logic. I should say however that I'm not the original author of the code :) – Mystogan Jul 05 '19 at 08:35
  • @vasily.sib Do you want to create an answer from your comment? (So I can select an answer and close the question.) – Mystogan Jul 05 '19 at 08:36
  • Possible duplicate of [How to work with Expression Trees not working using WCF since they are not serializable?](https://stackoverflow.com/questions/40361088/how-to-work-with-expression-trees-not-working-using-wcf-since-they-are-not-seria) Which happens to be the first hit on Google when searching for "WCF Expression". – Aron Jul 05 '19 at 08:46
  • 1
    @Mystogan, I'm not sure about the real reason why this field is excluded from the document, so I’d rather not answer this question :) Maybe someone with better knowladge of `WCF` come here and enlighten us. – vasily.sib Jul 05 '19 at 08:51
  • The client can reference the same models used by the service. https://stackoverflow.com/a/10384766/5101046. Now the client deserializes the response using the same model as the service. `IsHigh` doesn't need to be serialized. Another option is to extend the model that the client generates from the WSDL. Those should be generated as partial classes, so you can add your own file with different properties that won't get touched when the class is re-generated. Maybe you want a different definition for `IsHigh`. Otherwise it should be a serialized property of the class. – Scott Hannen Jul 05 '19 at 14:02

0 Answers0