none
WCF permission, XmlDocument RRS feed

  • Question

  • Hi, I have the method below that returns me "Unauthorized" in the client's environement, in my VM it works. I created a Literal to be used as LOG and the result is below the method. If I use Elevated Privileges it throws no error but also doenst return any XML.

    METHOD

            public XmlDocument MakeRequest(string requestUrl)
            {
                ltlLogMR.Text = "<p><p><p><p>------------------------------------------------------------------<br>" +
                                        "<b>MakeRequest()</b><br>Xln.326<br><b>requestUrl: </b>" + requestUrl;
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                        HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                        ltlLogMR.Text += "<br>Xln.334 <br><b> request:</b> " + request;
                        request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                        ltlLogMR.Text += "<br>Xln.336 <br> <b>request.Credentials:</b> " + request.Credentials;
    
                        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                        ltlLogMR.Text += "<br>Xln.339 <br><b> response:</b> " + response;
                        xmlDoc.Load(response.GetResponseStream());
                        ltlLogMR.Text += "<br>Xln.341 <br><b> response.GetResponseStream():</b> " + response.GetResponseStream();
                        ltlLogMR.Text += "<br>Xln.342 <br><b> xmlDoc:</b> " + xmlDoc;
                    return (xmlDoc);
                }
                catch (Exception e)
                {
                    ltlLogMR.Text += "<b> Exception:</b> " + e.Message;
                    Console.WriteLine(e.Message);
    
                    Console.Read();
                    return null;
                }
            }

    LOG

    -----------------------------------------------------------------------------------------------------------------
    MakeRequest()
    Xln.326
    requestUrl: http://extranet-dev/_vti_bin/InAosWCFServiceTest.svc/GetAllSiteColl
    Xln.334 
    request: System.Net.HttpWebRequest
    Xln.336 
    request.Credentials: System.Net.SystemNetworkCredential Exception: The remote server returned an error: (401) Unauthorized.

    Friday, April 18, 2014 1:55 PM

Answers

  • You have a credential issue.  My normal recommendation is to put the URL into a IE manually and see what response you get.  The IE sometimes gives better error meswsages like you need to install a certificate.  Once you get the IE working if you still have issues then I would start using a sniffer like wireshark or fiddler to compare the HTTP headers between the IE that works and your application.  The IE is much more robust in handdling the connection that a simple HTTP.Request.  Yo umay need to add cookies or go through a proxy server which the IE automatically does while HTTP.Request you have to add into your code as additional instructions.

    jdweng

    Friday, April 18, 2014 2:14 PM