Skip to content

Commit

Permalink
Merge pull request #145 from ngraziano/99b87f07af0beed3a887
Browse files Browse the repository at this point in the history
Fix Service Model Xml Serialization and XMLAttributes
  • Loading branch information
atsushieno committed Aug 2, 2011
2 parents fc9e1be + 99b87f0 commit a5610cb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Expand Up @@ -65,6 +65,7 @@ private XmlReflectionMember CreateReflectionMember (MessagePartDescription partD
m.IsReturnValue = isReturnValue;
m.MemberName = partDesc.Name;
m.MemberType = partDesc.Type;
m.XmlAttributes = new XmlAttributes(partDesc.MemberInfo);
return m;
}

Expand Down
Expand Up @@ -34,7 +34,9 @@
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;

namespace MonoTests.System.ServiceModel.Description
Expand Down Expand Up @@ -119,6 +121,49 @@ public void XmlSerializerdRoundtrip ()
Assert.AreEqual ("test", t2.echo.msg, "#01");
Assert.AreEqual ("testtest", t2.body2, "#02");
}


[Test]
public void XmlSerializerdWithXmlAttribute()
{
TypedMessageConverter c = TypedMessageConverter.Create (
typeof (Test3), "http://tempuri.org/MyTest",
new XmlSerializerFormatAttribute ());


string xmlMessage = @"<s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope'
xmlns:a='http://www.w3.org/2005/08/addressing'>
<s:Header><a:Action s:mustUnderstand='1'>http://tempuri.org/MyTest</a:Action></s:Header>
<s:Body xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<test xmlns='urn:foo'>
<Id>OneID</Id>
<Element>
<Prop1 xmlns='urn:bar'>foo</Prop1>
<Prop2 xmlns='urn:bar'>2</Prop2>
</Element>
<Element>
<Prop1 xmlns='urn:bar'>bar</Prop1>
<Prop2 xmlns='urn:bar'>3</Prop2>
</Element>
</test>
</s:Body>
</s:Envelope>";

byte[] buffer = Encoding.UTF8.GetBytes(xmlMessage);
using (XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(buffer, XmlDictionaryReaderQuotas.Max))
{
Message messagedisk = Message.CreateMessage(reader, int.MaxValue, MessageVersion.Soap12);
Test3 obj = c.FromMessage(messagedisk) as Test3;
Assert.IsNotNull(obj);
Assert.AreEqual("OneID", obj.Id);
Assert.IsNotNull(obj.ArrayOfElement);
Assert.AreEqual(2, obj.ArrayOfElement.Length);
Assert.AreEqual("foo", obj.ArrayOfElement[0].Prop1);
Assert.AreEqual(3, obj.ArrayOfElement[1].Prop2);
}
}


}

[MessageContract (WrapperNamespace = "space", WrapperName = "MyName")]
Expand Down Expand Up @@ -146,4 +191,32 @@ public class Test2
[MessageBodyMember (Name = "body", Namespace = "urn:foo")]
public Echo Body { get; set; }
}

[MessageContract(WrapperName = "test",
WrapperNamespace = "urn:foo",
IsWrapped = true)]
public class Test3
{

[MessageBodyMember()]
[XmlElementAttribute()]
public string Id;

[MessageBodyMember()]
[XmlElement(Type = typeof(ElementType), ElementName = "Element")]
public ElementType[] ArrayOfElement;

}

[Serializable]
[XmlType(Namespace = "urn:bar")]
public class ElementType
{
[XmlElement(Order = 0)]
public string Prop1 { get; set; }

[XmlElement(Order = 1)]
public int Prop2 { get; set; }
}

}

0 comments on commit a5610cb

Please sign in to comment.