私は2つのクラスを持っています.1つは実装IXmlSerializable
し、もう1つはDataContract
属性を持っています:
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; }
}
それから私はサービスインターフェースを持っています
[ServiceContract]
public interface IFooBarService
{
[OperationContract]
void TestFoo(Foo toTest);
[OperationContract]
void TestListFoo(Foo[] toTest);
[OperationContract]
void TestBar(Bar toTest);
[OperationContract]
void TestListBar(Bar[] toTest);
}
そして、その実装は次のとおりです。
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 は、サービスを呼び出すために必要な xml を生成しました。TestListFoo
空の配列を受け取る場所への呼び出しを除いて、すべて正常に動作します
<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>
私は何が欠けていますか?私が必要とするものを達成することは可能ですか?DataContract
そうでない場合、実装するクラスに属性を追加するにはどうすればよいIXmlSerializable
ですか?
ありがとう