我已经定义了一个MessageContract
,以便通过WCF传输Stream
以及其他一些数据:
[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"/>
但是头文件数据类的属性没有出现在WSDL文件中。 我如何让他们出现?
答案 0 :(得分:0)
事实证明MessageContract
属性必须有public
setter才能被生成代码的代码看到:
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"/>
答案 1 :(得分:0)
DataContracts / DataMembers上的服务合同访问修饰符不起任何作用。处理WCF消息时,.NET setter和getter visibility修饰符是无关紧要的,只要你相应地标记它们:
//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; }
}