I have created a proxy class in c# using Wsdl.exe
from the WSDL structure.
I need to serialize the proxy class and send to an HttpWebRequest
.
This is the code I used to serialize the class
using (System.IO.Stream soapStream = new System.IO.FileStream(@"C:\SoapFormat.xml", System.IO.FileMode.OpenOrCreate))
{
System.Xml.Serialization.SoapReflectionImporter soapRefImp = new System.Xml.Serialization.SoapReflectionImporter();
System.Xml.Serialization.XmlTypeMapping xmlTypeMapping = soapRefImp.ImportTypeMapping(typeof(clsPerson));
System.Xml.Serialization.XmlSerializer xmlSerializer =
new System.Xml.Serialization.XmlSerializer(xmlTypeMapping);
xmlSerializer.Serialize(soapStream, p);
}
I am getting the xml as
<?xml version="1.0"?>
<clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1">
<FirstName xsi:type="xsd:string">Jeff</FirstName>
<MI xsi:type="xsd:string">A</MI>
<LastName xsi:type="xsd:string">Price</LastName>
</clsPerson>
I need to add soap envelope. how can i add in c#.
My output should be like this
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-i开发者_StackOverflow社区nstance">
<soapenv:Body>
<clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1">
<FirstName xsi:type="xsd:string">Jeff</FirstName>
<MI xsi:type="xsd:string">A</MI>
<LastName xsi:type="xsd:string">Price</LastName>
</clsPerson>
</soapenv:Body>
</soapenv:Envelope>
Do u need to create a string builder and add the soap envelope as string. then insert the xml into that string.
for eg
string s= "<body>"+ xml + "</body">
Any other option in c# to create soap envelope?
I need to send this soapenvelope to a webservice as httprequest.
Any helps appreciated.
this requires webservice not wcf.
thanks
supriya
精彩评论