WCF MessageContract 属性未显示在 WSDL 中
WCF MessageContract properties not showing up in the WSDL
我定义了一个 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"/>
但是 header 数据 class 的属性没有显示在 WSDL 文件中。
我如何让他们出现?
原来 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"/>
DataContracts/DataMembers 上的服务合同访问修饰符不起作用。 .NET setter 和 getter 可见性修饰符在处理 WCF 消息时无关紧要,只要您相应地标记它们:
//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; }
}
我定义了一个 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"/>
但是 header 数据 class 的属性没有显示在 WSDL 文件中。 我如何让他们出现?
原来 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"/>
DataContracts/DataMembers 上的服务合同访问修饰符不起作用。 .NET setter 和 getter 可见性修饰符在处理 WCF 消息时无关紧要,只要您相应地标记它们:
//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; }
}