Adding a custom SOAP header using c#
<p>I have created a proxy class in c# using <code>Wsdl.exe</code> from the WSDL structure.</p>

<p>I need to serialize the proxy class and send to an <code>HttpWebRequest</code>. </p>

<p>This is the code I used to serialize the class</p>

<pre><code>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);
}
</code></pre>

<p>I am getting the xml as</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1"&gt;
  &lt;FirstName xsi:type="xsd:string"&gt;Jeff&lt;/FirstName&gt;
  &lt;MI xsi:type="xsd:string"&gt;A&lt;/MI&gt;
  &lt;LastName xsi:type="xsd:string"&gt;Price&lt;/LastName&gt;
&lt;/clsPerson&gt;
</code></pre>

<p>I need to add soap envelope. how can i add in c#.</p>

<p>My output should be like this</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;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-instance"&gt;
    &lt;soapenv:Body&gt;
&lt;clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1"&gt;
      &lt;FirstName xsi:type="xsd:string"&gt;Jeff&lt;/FirstName&gt;
      &lt;MI xsi:type="xsd:string"&gt;A&lt;/MI&gt;
      &lt;LastName xsi:type="xsd:string"&gt;Price&lt;/LastName&gt;
    &lt;/clsPerson&gt;
    &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
</code></pre>

<p>Do u need to create a string builder and add the soap envelope as string.
then insert the xml into that string.</p>

<p>for eg</p>

<pre><code>string s= "&lt;body&gt;"+ xml  + "&lt;/body"&gt;
</code></pre>

<p>Any other option in c# to create soap envelope?</p>

<p>I need to send this soapenvelope to a webservice as httprequest.</p>

<p>Any helps appreciated.</p>

<p>this requires webservice not wcf.</p>

<p>thanks </p>

<p>supriya</p>
