System.Net.WebClient client = new System.Net.WebClient(); client.Credentials = new NetworkCredential("", ""); client.Headers[HttpRequestHeader.Authorization] = "Basic"; //-Connect To the web service Getting 401 error in following line using (System.IO.Stream stream = client.OpenRead("***?sap-client=200")) { }
public void InvokeService() { HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(@"*****?sap-client=200"); Req.Credentials = new NetworkCredential("***", "***", "***"); Req.Headers.Add(@"SOAP:Action"); Req.ContentType = "text/xml;charset=\"utf-8\""; Req.Accept = "text/xml"; Req.Method = "POST"; XmlDocument SOAPReqBody = new XmlDocument(); SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <soap:Body> <Addition xmlns=""http://tempuri.org/""> <a>" + 10 + @"</a> " + 20 + @" </Addition> </soap:Body> </soap:Envelope>"); using (Stream stream = Req.GetRequestStream()) { SOAPReqBody.Save(stream); } //Getting 401 error in following line using (WebResponse Serviceres = Req.GetResponse()) { using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream())) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)