Click here to Skip to main content
15,885,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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 19-Nov-19 23:15pm
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...

1 solution

Solved my self, by removing below property from HttpClientHandler class
C#
UseDefaultCredentials = true
 
Share this answer
 

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