Click here to Skip to main content
15,668,691 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am trying to access the SAP WSDL service in Even though I have put correct credentials it throws "The remote server returned an error: (401) Unauthorized." error. I am able to access the SAP service using SoapUI application with these same credentials on the same machine. I need to connect to VPN before accessing these SAP services. Not sure what is causing this problem.
Is there anything specific that needs to be done here?

What I have tried:

I have tried the following codes.
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.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="""" xmlns:xsi="""" xmlns:xsd="""">
                <Addition xmlns="""">
                  <a>" + 10 + @"</a>
                  " + 20 + @"
            using (Stream stream = Req.GetRequestStream())
            //Getting 401 error in following line
            using (WebResponse Serviceres = Req.GetResponse())
                using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))

NotTodayYo 12-Mar-21 16:19pm    
If you are sure the credentials are correct then you're probably missing a header. You'll have to check with whoever owns the webservice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900