Click here to Skip to main content
14,422,213 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 Asp.net 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("http://10.10.10.52:7148/DynamicsNav1/OData/");
                client.BaseAddress = uri;
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                

                string clarity_URL = "http://10.10.10.52:7148/DynamicsNav1/OData/ShopFloorTaskList";
                var response = client.GetAsync(clarity_URL).Result;

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


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

Please suggest us to work on IIS server.
Posted
Updated 20-Nov-19 0:15am
Comments
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 10.10.10.52 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