Soap call from Controller
public static void Execute(string NTID)
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:urn=""urn:sap-com:document:sap:rfc:functions"">
<soapenv:Header xmlns:wsa =""http://www.w3.org/2005/08/addressing"" >
<wsa:Action>urn:sap-com:document:sap:rfc:functions:Z_WS_TRAIN_HIST:Z_GET_TRAIN_HISTRequest
</wsa:Action></soapenv:Header>
<soapenv:Body>
<urn:Z_GET_TRAIN_HIST >
<IM_TBL_TRAIN_HIST_INPUT>
<item>
<NTID>" + NTID + @"</NTID>
<LEARNERID/>
<COURSETYPE>076107WPL02</COURSETYPE >
</item>
</IM_TBL_TRAIN_HIST_INPUT>
</urn:Z_GET_TRAIN_HIST>
</soapenv:Body>
</soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
/// <summary>
/// Create a soap webrequest to [Url]
/// </summary>
/// <returns></returns>
public static HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest =
(HttpWebRequest)WebRequest.Create(@"https://integnet.lmaero.lmco.com/training_history_outbound");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:urn=""urn:sap-com:document:sap:rfc:functions"">
<soapenv:Header xmlns:wsa =""http://www.w3.org/2005/08/addressing"" >
<wsa:Action>urn:sap-com:document:sap:rfc:functions:Z_WS_TRAIN_HIST:Z_GET_TRAIN_HISTRequest
</wsa:Action></soapenv:Header>
<soapenv:Body>
<urn:Z_GET_TRAIN_HIST >
<IM_TBL_TRAIN_HIST_INPUT>
<item>
<NTID>" + NTID + @"</NTID>
<LEARNERID/>
<COURSETYPE>076107WPL02</COURSETYPE >
</item>
</IM_TBL_TRAIN_HIST_INPUT>
</urn:Z_GET_TRAIN_HIST>
</soapenv:Body>
</soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
/// <summary>
/// Create a soap webrequest to [Url]
/// </summary>
/// <returns></returns>
public static HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest =
(HttpWebRequest)WebRequest.Create(@"https://integnet.lmaero.lmco.com/training_history_outbound");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
Comments