我在数据合同中有一个字符串数组,如下所示
[DataMember(Name = "photos", IsRequired = true, Order = 3)]
public string[] photos { get; set; }
在 WCF REST 服务调用中,我在此字符串数组的 xml 输入下方传递
<photos>
<string>http://localhost:13169/MainPortal/ContentLibrary/21/58/1227132014-bmw-x1_100426158_m.jpg</string>
<string>http://localhost:13169/MainPortal/ContentLibrary/21/58/122713bmw2.jpg</string>
<string>http://localhost:13169/MainPortal/ContentLibrary/21/58/122713bmw3.jpg</string>
<string>http://localhost:13169/MainPortal/ContentLibrary/21/58/122713BMW_Hamann_Laguna_Seca.jpg</string><string>http://localhost:13169/MainPortal/ContentLibrary/21/58/1227132014-BMW-X1-SUV-sDrive-28i-4dr-4x2-Sports-Activity-Vehicle-Exterior-2.png</string>
</photos>
我的客户端代码能够通过在 HttpWebRequest 中传递 xml 来毫无问题地进行 WebService 调用,从服务中我可以看到除此字符串数组之外的所有其他数据。我是否在 DataContract 中遗漏了一些东西来序列化数组。请帮忙
尝试如下 CollectionDataContract 仍然没有运气
[CollectionDataContract(Name = "photos")]
public class Photos : Collection<string>
还添加了 KnownTypes 但序数类型不需要
[KnownType(typeof(string[]))]
public class PublishPhotos
{
这是完整的数据合约类
[DataContract(Namespace = "http://myurl.com/Publisher")]
[KnownType(typeof(string[]))]
public class PublishPhotos
{
[DataMember(Name = "publicationId", IsRequired = true, Order = 0)]
public int publicationId { get; set; }
[DataMember(Name = "issueId", IsRequired = true, Order = 1)]
public string issueId { get; set; }
[DataMember(Name = "contentId", IsRequired = true, Order = 2)]
public string contentId { get; set; }
[DataMember(Name = "photos", IsRequired = true, Order = 3)]
public Photos photos { get; set; }
}