1 Message newMessage = null;
2 MessageBuffer msgbuf = reply.CreateBufferedCopy(int.MaxValue);
3
4 var copy = msgbuf.CreateMessage();
5
6
7 XmlDocument doc = new XmlDocument();
8
9 MemoryStream ms = new MemoryStream();
10
11 XmlWriter writer = XmlWriter.Create(ms);
12
13 copy.WriteMessage(writer);
14
15 writer.Flush();
16
17 ms.Position = 0;
18
19 doc.Load(ms);
1 /// <summary>
2 /// Se cambia el mensaje Soap, cambiando los atributos href por los valores correspondiente
3 /// </summary>
4 /// <param name="xmldoc"></param>
5 private void ChangeMessage(ref XmlDocument xmldoc)
6 {
7 //Se transforma a Xdocument para realizar LinQ
8 XDocument xdoc = ToXDocument(xmldoc);
9
10
11 List<string> href = new List<string>();
12 Dictionary<string, string> id = new Dictionary<string, string>();
13 Dictionary<string, XAttribute> type = new Dictionary<string, XAttribute>();
14
15 //Se buscan los elementpos con atributo id
16
17 IEnumerable<XElement> elList =
18 from el in xdoc.Descendants()
19 where el.Attribute("id") != null
20 select el;
21 foreach (XElement el in elList)
22 {
23 if (el.Attribute("id").Value.StartsWith("ID_"))
24 {
25 id.Add(el.Attribute("id").Value.ToString(), el.Value);
26 type.Add(el.Attribute("id").Value.ToString(), el.Attribute("{http://www.w3.org/2001/XMLSchema-instance}type"));
27 }
28 }
29
30 //Se buscan los elementos con atributo href y se sustituye por el valor que se
31 IEnumerable<XElement> elListHref =
32 from el in xdoc.Descendants()
33 where el.Attribute("href") != null
34 select el;
35 foreach (XElement el in elListHref)
36 {
37 string value = id[el.Attribute("href").Value.ToString().Replace("#", "")];
38 el.Add(new XAttribute(type[el.Attribute("href").Value.ToString().Replace("#", "")].Name, type[el.Attribute("href").Value.ToString().Replace("#", "")].Value));
39 el.Attribute("href").Remove();
40 el.Value = value;
41 }
42 xmldoc = ToXmlDocument(xdoc);
43 }
1 ms.SetLength(0);
2
3 writer = XmlWriter.Create(ms);
4
5 doc.WriteTo(writer);
6
7 writer.Flush();
8
9 ms.Position = 0;
10
11 XmlReader reader = XmlReader.Create(ms);
12
13 reply = Message.CreateMessage(reader, int.MaxValue, reply.Version);