Click here to Skip to main content
14,447,269 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

I tried to invoking Dynamics Nav Rest/OData web service in and it's working perfectly when I was running in my local application.

After I published to IIS Server it's not getting the result it's throwing error Internal Server Error.

What I have tried:

I tried below code

public string GetData()

            NetworkCredential networkCredential = new NetworkCredential("bojjaiah.thoti", "pass@word1", "testserver");

            using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true, Credentials = networkCredential, PreAuthenticate = true }))
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
                Uri uri = new Uri("");
                client.BaseAddress = uri;
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                string clarity_URL = "";
                var response = client.GetAsync(clarity_URL).Result;

                string responseString = response.Content.ReadAsStringAsync().Result;
                return responseString;

I don't know what is the difference between local application and Hosted Application.

Please suggest us to work on IIS server.
Updated 20-Nov-19 0:15am
Kornfeld Eliyahu Peter 20-Nov-19 2:33am
Hunt for the actual error - look into the Event Log, check if that IP is still accessible from the server you published to, add trace massages with some try-catch... All the ugly tools to debug in production...
Bojjaiah 20-Nov-19 3:29am
It's not an exception `client.GetAsync(clarity_URL).Result` is returning false with internal server error.
Kornfeld Eliyahu Peter 20-Nov-19 3:33am
And that URL is yours?
Bojjaiah 20-Nov-19 3:42am
Yes, within my network. it's accessed entire network.
Kornfeld Eliyahu Peter 20-Nov-19 3:44am
I mean the code that runs there is yours? Can you check it?
The fact that from one site (development) you can and from an other site (publish) you can not looks to me as a network related problem...
Richard MacCutchan 20-Nov-19 3:40am
Most likely the URL is not valid when you publish on the server, since is the IP address of your local PC and not the web server.
Bojjaiah 20-Nov-19 3:44am
It is published another server, but still, I can add web reference as well it will work.
Richard MacCutchan 20-Nov-19 4:01am
So what is your problem?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Solved my self, by removing below property from HttpClientHandler class
UseDefaultCredentials = true

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100