I have some xml generated from the XML Serializer ..How can I convert it to SOAP XML ?...I am trying to do it ASP.NET C#...please help me out
+1
A:
You will just need to create a data class that can be serialized by both the XMLSerializer and the SOAPFormatter. This likely means you will need a public class with public properties for the XMLSerializer and you will need to add the Serializable attribute for the SOAPFormatter. Otherwise, it is pretty straight forward.
I created a Naive example to illustrate what I mean:
[Serializable]
public class MyData
{
public int MyNumber { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (MemoryStream stream = new MemoryStream())
{
MyData data = new MyData() { MyNumber = 11, Name = "StackOverflow" };
XmlSerializer serializerXML = new XmlSerializer(data.GetType());
serializerXML.Serialize(stream, data);
stream.Seek(0, SeekOrigin.Begin);
data = (MyData)serializerXML.Deserialize(stream);
// We're cheating here, because I assume the SOAP data
// will be larger than the previous stream.
stream.Seek(0, SeekOrigin.Begin);
SoapFormatter serializerSoap = new SoapFormatter();
serializerSoap.Serialize(stream, data);
stream.Seek(0, SeekOrigin.Begin);
data = (MyData)serializerSoap.Deserialize(stream);
}
}
}
Scott P
2010-07-15 15:02:54
I cannot use SoapFormatter it seems it was deprecated i guess..in .net 3.5/4.0
Misnomer
2010-07-15 15:38:49
I guess you need to provide more information. You likely need to get the service specification (WSDL etc) from them. You can use WCF to inter-operate with SOAP services once you have the service description.
Scott P
2010-07-15 23:36:49
+1
A:
There's no such thing as "raw XML" and "SOAP XML".
What are you trying to accomplish? If you're just trying to return XML as a response from a web service, then just get it into an XmlDocument or XDocument, and just return the root element:
[WebMethod]
public XmlElement ReturnXml()
{
XmlDocument doc = new XmlDocument();
doc.Load(fromSomewhere);
return doc.DocumentElement;
}
John Saunders
2010-07-15 15:09:31
hmm...i was actually wanting to send some data over to an url web service...as xml...so i thought i should use SOAP header or something to enacapsulate it...so i was calling it like "SOAP XML"
Misnomer
2010-07-15 15:40:47
What does the web service say it wants to receive? Is there a WSDL file telling you the format? Is there documentation?
John Saunders
2010-07-15 16:28:36
there is unfortunately no documentation...all they expect is xml my guess...
Misnomer
2010-07-15 19:31:19
@VJ: that makes no sense. They _must_ tell you what kind of XML they want.
John Saunders
2010-07-15 19:36:43