0

I have defined a MessageContract in order to transfer a Stream along with some other data via WCF:

[MessageContract]
public class DTSetGeotagImageMessage
{
    [MessageHeader(MustUnderstand = true)]
    public DTGeotagImageFileInfo GeotagImageFileInfo;

    [MessageBodyMember(Order = 1)]
    public Stream FileData;
}

public class DTGeotagImageFileInfo
{ //All these properties are not showing up in the WSDL:
    public long? GeotagID { get; internal set; }
    public string GeotagGuid { get; internal set; }
    public string ImageGuid { get; internal set; }
    public long GeotagFieldId { get; internal set; }
    public double Lat { get; internal set; }
    public double Lon { get; internal set; }
}

WSDL:

<xs:complexType name="DTGeotagImageFileInfo">
 <xs:sequence/>
</xs:complexType>
<xs:element name="DTGeotagImageFileInfo" nillable="true" type="tns:DTGeotagImageFileInfo"/>

But the properties of the header data class is not showing up in the WSDL file. How do I get them to show up?

Aske B.
  • 6,419
  • 8
  • 35
  • 62

2 Answers2

0

It turns out MessageContract properties must have a public setter in order to be seen by the code that generates the code:

public class DTGeotagImageFileInfo
{
    public long? GeotagID { get; set; }
    public string GeotagGuid { get; set; }
    public string ImageGuid { get; set; }
    public long GeotagFieldId { get; set; }
    public double Lat { get; set; }
    public double Lon { get; set; }
}

WSDL:

<xs:complexType name="DTGeotagImageFileInfo">
    <xs:sequence>
     <xs:element minOccurs="0" name="GeotagFieldId" type="xs:long"/>
     <xs:element minOccurs="0" name="GeotagGuid" nillable="true" type="xs:string"/>
     <xs:element minOccurs="0" name="GeotagID" nillable="true" type="xs:long"/>
     <xs:element minOccurs="0" name="ImageGuid" nillable="true" type="xs:string"/>
     <xs:element minOccurs="0" name="Lat" type="xs:double"/>
     <xs:element minOccurs="0" name="Lon" type="xs:double"/>
    </xs:sequence>
   </xs:complexType>
   <xs:element name="DTGeotagImageFileInfo" nillable="true"
       type="tns:DTGeotagImageFileInfo"/>
Aske B.
  • 6,419
  • 8
  • 35
  • 62
0

Service Contract access modifiers on DataContracts/DataMembers do not play any role. .NET setter and getter visibility modifier are irrelevant when dealing with WCF messages, as long as you tag them accordingly:


//Tag DataContract and DataMember for serialization
[DataContract]
public class DTGeotagImageFileInfo
{ 
    [DataMember]
    public long? GeotagID { get; internal set; }
    [DataMember]
    public string GeotagGuid { get; internal set; }
    [DataMember]
    public string ImageGuid { get; internal set; }
    [DataMember]
    public long GeotagFieldId { get; internal set; }
    [DataMember]
    public double Lat { get; internal set; }
    [DataMember]
    public double Lon { get; internal set; }
}
Aske B.
  • 6,419
  • 8
  • 35
  • 62
Suhail
  • 71
  • 4
  • It appears you are right, which makes more sense. But you could have illustrated the point more easily by letting the setters be `internal` (as I had them originally), which still works. So I guess my solution only works because WCF automatically detects public properties as `DataMember`s. – Aske B. Apr 24 '18 at 18:10