Hi guys,
I was given a task to read soap envelope and do some operations on it. Here is how I achieved it
[HttpPost]
[ActionName("CDDService")]
[Route("api/test/CDDService")]
public void CDDService()
{
var b = RequestBody(HttpContext.Current.Request.InputStream);
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(b);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(soapEnvelop.NameTable);
nsmgr.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope");
nsmgr.AddNamespace("sch", "http://ws.test.com/rti/cdd/schema");
nsmgr.AddNamespace("wsse", "http://dtest.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
nsmgr.AddNamespace("wsu", "http://dtest.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
string Username = soapEnvelop.DocumentElement.SelectSingleNode("//wsse:Username",nsmgr).InnerText;
string password = soapEnvelop.DocumentElement.SelectSingleNode("//wsse:Password",nsmgr).InnerText;
var cddRequest = soapEnvelop.DocumentElement.SelectSingleNode("//sch:cddRequest",nsmgr);
string clientCandidateID = cddRequest.Attributes["clientCandidateID"].Value;
string clientID = cddRequest.Attributes["clientID"].Value;
string firstname = cddRequest.SelectSingleNode("candidateName/firstName").InnerText;
string lastname = cddRequest.SelectSingleNode("candidateName/lastName").InnerText;
string email = cddRequest.SelectSingleNode("webAccountInfo/email").InnerText;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml;charset=utf-8";
HttpContext.Current.Response.Write(@"<pingResponse><status>Success</status></pingResponse>");
HttpContext.Current.Response.End();
}
private static string RequestBody(Stream InputStream)
{
var bodyStream = new StreamReader(InputStream);
bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
var bodyText = bodyStream.ReadToEnd();
return bodyText;
}
Hope it helps!
I was given a task to read soap envelope and do some operations on it. Here is how I achieved it
[HttpPost]
[ActionName("CDDService")]
[Route("api/test/CDDService")]
public void CDDService()
{
var b = RequestBody(HttpContext.Current.Request.InputStream);
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(b);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(soapEnvelop.NameTable);
nsmgr.AddNamespace("soap", "http://www.w3.org/2003/05/soap-envelope");
nsmgr.AddNamespace("sch", "http://ws.test.com/rti/cdd/schema");
nsmgr.AddNamespace("wsse", "http://dtest.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
nsmgr.AddNamespace("wsu", "http://dtest.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
string Username = soapEnvelop.DocumentElement.SelectSingleNode("//wsse:Username",nsmgr).InnerText;
string password = soapEnvelop.DocumentElement.SelectSingleNode("//wsse:Password",nsmgr).InnerText;
var cddRequest = soapEnvelop.DocumentElement.SelectSingleNode("//sch:cddRequest",nsmgr);
string clientCandidateID = cddRequest.Attributes["clientCandidateID"].Value;
string clientID = cddRequest.Attributes["clientID"].Value;
string firstname = cddRequest.SelectSingleNode("candidateName/firstName").InnerText;
string lastname = cddRequest.SelectSingleNode("candidateName/lastName").InnerText;
string email = cddRequest.SelectSingleNode("webAccountInfo/email").InnerText;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml;charset=utf-8";
HttpContext.Current.Response.Write(@"<pingResponse><status>Success</status></pingResponse>");
HttpContext.Current.Response.End();
}
private static string RequestBody(Stream InputStream)
{
var bodyStream = new StreamReader(InputStream);
bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
var bodyText = bodyStream.ReadToEnd();
return bodyText;
}
Hope it helps!
1 comment:
Welcome To Online Shopping Lucky Winner, ELIGIBILITY FOR PARTICIPATION, If you are an individual legal resident India and are 18 or older at the time of entry, you are eligible to enter the Sweepstakes. Our employees, their immediate family members (spouses, domestic partners, parents, grandparents, siblings, children and grandchildren), and our affiliates, advisors or advertising/promotion agencies (and their immediate family members) are not eligible to enter the Sweepstakes.
Post a Comment
Comments are welcome, Please join me on my Linked In account
http://in.linkedin.com/pub/ritesh-tandon/21/644/33b