我有一个WCF Rest服务,我使用WCF REST服务模板40创建 . 它的工作正常分离形成任何[DataMember]为空的问题,Response XML格式不正确 . 例如,如果[Datamember Name =“experimentnumber”]为空或空 . 我想要接下来的
<section><a:content><a:created>2011-12-15T08:03:11</a:created><a:documentid>1935</a:documentid><a:experimentnumber></a:experimentnumber><a:lastedited>2011-12-15T08:03:11</a:lastedited><a:sectionauthor>ZLATAN</a:sectionauthor><a:sectiontitle>Data files</a:sectiontitle></a:content></section>
但我明白了
<section><a:content><a:created>2011-12-15T08:03:11</a:created><a:documentid>1935</a:documentid><a:experimentnumber><a:lastedited>2011-12-15T08:03:11</a:lastedited><a:sectionauthor>ZLATAN</a:sectionauthor><a:sectiontitle>Data files</a:sectiontitle></a:experimentnumber></a:content></section>
这是我的服务 Contract
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class MyClass
然后在服务类我有这个收集 Contract
[CollectionDataContract(Name = "sections")]
public class Sections : List<MyClass.Model.Section>
{ }
然后我有 endpoints
[OperationContract]
public Sections GetSections(string typeid, string title, string lastedited)
Section类具有此datacontract
[DataContract (Name="Section")]
public class Section
experimentnumber是一个字符串datamember
[DataMember(Name = "experimentnumber")]
public string ExperimentNumber
{
get
{
return this.experimentnumber;
}
set
{
}
}