Amazon Ad

Thursday 1 February 2018

How to read soap envelope in c#

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!

Saturday 27 January 2018

How to solve net::ERR_CONTENT_DECODING_FAILED in ASP.NET

Guys,

It took me three days to solve one simple problem which was caused due to ajax post form posting data to .asmx service webmethod. This error usually happens when there is an implementation of dynamic/stati compression in the project for ex. gzip or deflate compression. The code which worked is given below:

$.ajax({
                    url: 'test.asmx',
                    dataType:"json",
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    data: formData,
                    success: function (data) {
                        console.log(data);
                        data = data.d;
                        console.log('inside success response Text is '+this.responseText);
                        console.log(data);
                        console.log('Success');
                        checkData(this.responseText);
                    },
                    error: function (a, b, c) { console.log('Error');checkData(a.responseText); console.log(a); console.log(b); console.log(c); }
                });

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...