0

I've defined the following struct in my WCF service:

[Serializable]
[DataContract]
public struct CompositeKey : 
   IComparable, IComparable<CompositeKey>, IEquatable<CompositeKey>
{
    [DataMember]
    public long Primary { get; private set; }

    [DataMember]
    public byte Secondary { get; private set; }

   //others
}

which is used as members of some other data contract:

[DataContract]
public class PatternFrequencyArgs
{
  [DataMember(IsRequired=true, EmitDefaultValue=false)]
  public CompositeKey PatternKey { get; set; }

  [DataMember(IsRequired = true)]
  public CompositeKey SessionStatKey { get; set; }

  [DataMember]
  public int Frequency { get; set; }
}

On the client side, wsutil.exe generates this struct:

typedef struct PatternFrequencyArgs 
{
    int Frequency;
    struct CompositeKey* PatternKey;     //why pointer?
    struct CompositeKey* SessionStatKey; //why pointer?
} PatternFrequencyArgs;

As you can see, the CompositeKey members are generated as pointers. I don't want them to be pointers. How to avoid that and instead generate them as non-pointer members?

The relevant XSD from which the above struct is generated is this (I guess that):

<xs:complexType name="PatternFrequencyArgs">
    <xs:sequence>
      <xs:element minOccurs="0" name="Frequency" type="xs:int" />
      <xs:element xmlns:q6="http://schemas.etc..." name="PatternKey" type="q6:CompositeKey">
        <xs:annotation>
          <xs:appinfo>
            <DefaultValue EmitDefaultValue="false" xmlns="http://schemas.etc..." />
          </xs:appinfo>
        </xs:annotation>
      </xs:element>
      <xs:element xmlns:q7="http://schemas.etc..." name="SessionStatKey" type="q7:CompositeKey" />
    </xs:sequence>
</xs:complexType>
Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • Why would you define a value type for use as a DTO? Does this provide some value that I've not yet come across? – M.Babcock Mar 06 '13 at 05:34
  • @M.Babcock: Why? Can't I define value-type as data member? I defined it as `struct` because it is easy to make copy of object of value-type, which helps in other places, such as C# client (as well as in services). I'm thinking of achieving the same for C++ client also. I don't like to use `new` when calling service methods from C++, or at least want to avoid where it is not absolutely necessary. – Nawaz Mar 06 '13 at 05:39
  • I had just never come across such an implementation and doesn't really make sense in my mind to ever serialize a complex value type. Just a guess but if you change it to a class you probably won't have the problem anymore. :) – M.Babcock Mar 06 '13 at 05:43
  • @M.Babcock: I tried that also. Reference-type or value-type, it doesnt make any difference in generated C code. However XSD code is a bit different. It has `nillable="true"` attribute also. – Nawaz Mar 06 '13 at 05:52

0 Answers0