jeudi 22 mars 2018

system.net.webexception: the remote server returned an error: [404] not found xamarin android

I am creating an android app which will POST a soap envelop and get the response as xml which i will parse. but whenever i am triggering the method i am getting an error "system.net.webexception: the remote server returned an error: [404] not found" where as everything seems to be correct i followed this method from here

below is my code and screenshothere i have enabled the internet permission and my app is connected to wifi

login.Click += delegate
            {

                Execute();

                StartActivity(new Intent(this, typeof(TradeType)));
                this.OverridePendingTransition(Resource.Animation.abc_slide_in_top,Resource.Animation.abc_slide_out_bottom);
            };
        }
        public void Execute()
        {
            passparams = pass.Text.ToString();
            userparams = user.Text.ToString();
            HttpWebRequest request = CreateWebRequest("http://192.168.123.240/ClearSourceAndroid/FusionService.svc", "http://CTRMService/CTRM/CommonService/AuthenticateUser");
            XmlDocument soapenvelopxml = new XmlDocument();

            soapenvelopxml.LoadXml(@"
            <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ctrm=""http://CTRMService/CTRM"" xmlns:dtom=""http://schemas.datacontract.org/2004/07/DTOModelLayer.DataContracts"">
            <soapenv:Header>
            <DataHeader xmlns='http://CTRMService/CTRM'>AuthenticateUser</DataHeader>
            </soapenv:Header>
            <soapenv:Body>
            <ctrm:AuthenticateUser>
            <ctrm:request>
            <dtom:Password>mNVSqt3FyQc=</dtom:Password>
            <dtom:Username>Admin</dtom:Username>
            </ctrm:request>
            </ctrm:AuthenticateUser>
            </soapenv:Body>
            </soapenv:Envelope>");


             using (Stream stream = request.GetRequestStream())
             {
                soapenvelopxml.Save(stream);
             }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {

                    string soapresult = rd.ReadToEnd();
                    response.Close();
                    pass.Text = soapresult;
                }

            }

        }

        private HttpWebRequest CreateWebRequest(string url,string soapAction)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.ContentType = "application/soap+xml;charset=UTF-8;action=\""+action+"\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }




Aucun commentaire:

Enregistrer un commentaire