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:
test
test
test
30
test
test
TestData
testident
11
The class of my source code looks like this:
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
Sebastian LoerPosted Feb 14, 2022, 8:32 AM
Muhammad Imran AnsariPosted Feb 12, 2022, 8:26 PM
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:
Sachin SinghPosted Feb 12, 2022, 2:06 PM