I have two classes, one implements IXmlSerializable
and one has DataContract
attribute:
public class Foo : IXmlSerializable
{
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
reader.MoveToContent();
XElement element = (XElement)XNode.ReadFrom(reader);
if (element.Element("Foo") != null)
element = element.Element("Foo");
Property = Convert.ToInt32(element.Element("Property").Value);
}
public void WriteXml(XmlWriter writer)
{
var element = new XElement("Foo");
element.Add(new XElement("Property", Property));
element.WriteTo(writer);
}
public int Property { get; set; }
}
[DataContract]
public class Bar
{
[DataMember]
public int Property { get; set; }
}
Then I have the service interface
[ServiceContract]
public interface IFooBarService
{
[OperationContract]
void TestFoo(Foo toTest);
[OperationContract]
void TestListFoo(Foo[] toTest);
[OperationContract]
void TestBar(Bar toTest);
[OperationContract]
void TestListBar(Bar[] toTest);
}
And its implementation as:
public class FooBarService : IFooBarService
{
public void TestFoo(Foo toTest)
{
var a = toTest.Property;
}
public void TestListFoo(Foo[] toTest)
{
foreach (var item in toTest)
{
var x = item.Property;
}
}
public void TestBar(Bar toTest)
{
var a = toTest.Property;
}
public void TestListBar(Bar[] toTest)
{
foreach (var item in toTest)
{
var x = item.Property;
}
}
}
SOAP UI generated the xml needed to call the service. All works correctly except the call to TestListFoo
where I receive an empty array
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:com="http://schemas.datacontract.org/2004/07/Com.Panotec.Remote.Core.WebService" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soapenv:Header/>
<soapenv:Body>
<tem:TestListFoo>
<tem:toTest>
<Foo>
<Property>1</Property>
</Foo>
<Foo>
<Property>1</Property>
</Foo>
<Foo>
<Property>1</Property>
</Foo>
<Foo>
<Property>1</Property>
</Foo>
</tem:toTest>
</tem:TestListFoo>
</soapenv:Body>
</soapenv:Envelope>
What am I missing? Is it possible to achieve what I need?
If not, how can I add the DataContract
attribute to the class that implements IXmlSerializable
?
Thanks