Hey guys,
i have a problem with the serialization of an array during a SOAP request:
The interesting part of the incoming Message looks like this:
Code
test
test
test
30
test
test
TestData
testident
11The class of my source code looks like this:
C#
public class wait4GetType : headerRequest
{
[XmlElement("get")] public getType[] get { get; set; }
[XmlAttribute] public int maxWaitTime { get; set; }
[XmlIgnore] public bool maxWaitTimeSpecified { get; set; }
public override string AddToString(int indent)
{
var s = base.AddToString(indent);
indent++;
AddToString(indent, ref s, "get", get);
AddToString(indent, ref s, "maxWaitTime", maxWaitTime);
AddToString(indent, ref s, "maxWaitTimeSpecified", maxWaitTimeSpecified);
return s;
}
}The problem is that my process expects an extra node
.....
Without this extra node, the element
How can i change this behaviour?
Best Regards

Sachin SinghRank #66 · 26.2K reputationPosted Feb 12, 2022, 9:06 AM EST
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 12, 2022, 3:26 PM EST
Just modified your code with attribute of ElementName like:
[XmlElement(ElementName = "get")]
public getType[] get { get; set; }
getType gType1 = new getType() { userName = "userName1", passWord ="****", objectType = "Obj1" };
getType gType2 = new getType() { userName = "userName2", passWord = "****", objectType = "Obj2" };
getType[] gTypeArray = new getType[2] { gType1, gType2 };
wait4GetType wait = new wait4GetType() { userName = "John", passWord = "****", get = gTypeArray, maxWaitTime = 10, maxWaitTimeSpecified = true };
var xml = "";
John
****
10
userName1
****
Obj1
userName2
****
Obj2
using (StringWriter stringwriter = new System.IO.StringWriter())
{
var serializer = new XmlSerializer(wait.GetType());
serializer.Serialize(stringwriter, wait);
xml = stringwriter.ToString();
}
Output:
Sebastian Loer14 reputationPosted Feb 14, 2022, 3:32 AM EST