Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing enum in WCF service
    text
    copied!<p>I have a WCF web service written in c# I have an enum</p> <pre><code>[DataContract(Namespace = "NameSpace")] public enum State { [EnumMember] NotAvailable = 1, [EnumMember] RunningTests = 3, [EnumMember] ReadyForTests = 4, [EnumMember] HungOrBroken = 5 } </code></pre> <p>Then I run following commands to generate .h, .cpp files I can use in my MFC application.</p> <pre><code>svcutil.exe /t:metadata &lt;webservice dll&gt; WSUtil.exe /prefix:Ws *.wsdl *.xsd </code></pre> <p>Above commands generate files that have:</p> <pre><code>typedef enum WsState { WsStateHungOrBroken = 0, WsStateNotAvailable = 1, WsStateReadyForTests = 2, WsStateRunningTests = 3, } </code></pre> <p>I understand why the enum values don't match exactly (<a href="http://social.msdn.microsoft.com/Forums/en/wwsapi/thread/2aee66b6-a387-44f3-88cb-71892b148822" rel="nofollow">info</a>). Everything works as expected except that when I pass WsStateHungOrBroken to web service, it cannot interpret it correctly and simply convert it to 0. It should really be 5 which is how it is defined in web service.</p> <p>If anyone can explain to me why it is like this or how i can debug further, that would be useful. As a note, I've tried SvcTraceViewer but no luck in finding out what data is being passed in between service and my application.</p> <p><strong>Edit</strong>: Found solution at <a href="http://thorarin.net/blog/post/2010/08/08/Controlling-WSDL-minOccurs-with-WCF.aspx#comment" rel="nofollow">http://thorarin.net/blog/post/2010/08/08/Controlling-WSDL-minOccurs-with-WCF.aspx#comment</a> By default all WCF method parameters are IsRequired=False and when enum value is 0, WCF treats this as empty value and don't pass it to service at all and service use default value. Making all parameters required fixes the issue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload