Create SOAP envelope in

QuestionsCategory: C#Create SOAP envelope in
XorientXorient asked 5 months ago

How to Create SOAP envelope in

1 Answers
Best Answer
Mahesh DeshmaneMahesh Deshmane answered 5 months ago

To get the data from service via SOAP, SOAP envelope should contains one Header element and one Body elements .
Some case it also needs encoding style but it’s optional
WSDL  provides more information about what are prerequisite like encoding styles or attributes to call the service.
Here is C# code snippet below which creates SOAP envelope.

private static XmlDocument CreateSoapEnvelope()
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
            <soap:Envelope xmlns:soap="""" xmlns:xsi="""" xmlns:xsd="""">
            < soap:Body >
            < WebMethod1 xmlns = """">
            < Parameter1 > param1 </ Parameter1 >
            < Parameter2 > param2 </ Parameter2 >
            < Parameter3 > param3 </ Parameter3 >
            </ Method >            </ soap:Body >
            </ soap:Envelope > ");
     return soapEnvelopeXml;

Note: make sure to change the method name, service name and parameters in Body elements from above code snippet before use.