looking for some solutions? You are welcome.

SOLVED: Windows service calling WebGet method returns 400 error

kristech:

I have a service that runs a c# method to sync a database with active directory at a specified interval. This code has worked in a test environment and now putting it on a different server it is returning the following message:

The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.

The help page looks like this:

enter image description here

But the "SyncActiveDirectory" URI is giving me this error:

enter image description here

This is a new server. Maybe i am missing something that needs to be installed or a setting in IIS? Any help would be much appreciated.

EDIT: Here is the method that called the webget:

private void SyncActiveDirectoryServiceCall()
        {
            WriteIntoLogFile("Start _schedulerService.SyncActiveDirectoryServiceCall()");

            try
            {
                var reader = new AppSettingsReader();
                var serviceurl = reader.GetValue("ServiceUrl", typeof(string));
                var client = new RestSharp.RestClient(serviceurl.ToString());
                var request = new RestSharp.RestRequest("SyncActiveDirectory", RestSharp.Method.GET);
                var response = client.Execute(request);
                WriteIntoLogFile(response.Content);
            }
            catch (WebException ex)
            {
                using (WebResponse response = ex.Response)
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;

                    WriteIntoLogFile("Error code: " + httpResponse.StatusCode);

                    using (Stream data = response.GetResponseStream())
                    using (var reader = new StreamReader(data))
                    {
                        string text = reader.ReadToEnd();
                        WriteIntoLogFile("STREAMED: " + text);
                    }
                }
                WriteIntoLogFile("TRY-CATCH: " + ex.ToString());
            }
            WriteIntoLogFile("End _schedulerService.SyncActiveDirectoryServiceCall()");

        }

And here is the method being called:

namespace SyncActiveDirectory
{
    public class SyncLocalWithLDAP : ISyncLocalWithLDAP
    {
        private List<GenericUser> users { get; set; }
        private List<GenericUser> roles { get; set; }
        [WebGet(UriTemplate = "SyncActiveDirectory")]
        public void SyncActiveDirectory()
        {
            string constr = GetConnectionStringValue("ProteusMMXCustomerDB");
            string usr = GetAppsettingValue("ldap_login_username");
            string pss = GetAppsettingValue("ldap_login_password");
            string filePath = string.Empty;
            ActiveDirectoryWrapper wrapper = new ActiveDirectoryWrapper();
            if (!Directory.Exists(WebConfigurationManager.AppSettings["LogFolderPath"] + "ServiceLog"))
            {
                Directory.CreateDirectory(WebConfigurationManager.AppSettings["LogFolderPath"] + "ServiceLog");
            }
            if (!File.Exists(WebConfigurationManager.AppSettings["LogFolderPath"] + "ServiceLog" + "/" + "SyncLog.txt"))
            {
                File.Create(WebConfigurationManager.AppSettings["LogFolderPath"] + "ServiceLog" + "/" + "SyncLog.txt").Dispose();
            }

            filePath = WebConfigurationManager.AppSettings["LogFolderPath"] + "ServiceLog" + @"\" + "SyncLog.txt";

            using (StreamWriter w = File.AppendText(filePath))
            {
                Log("Constr - " + constr + " , u - " + usr + " p - " + pss, w);
                try
                {
                    Log("Start sync outer", w);
                    SyncLocalWithLDAP_Users_Roles(constr, usr, pss, w);
                    Log("End sync outer", w);
                }
                catch (Exception ex)
                {
                    Log("Error: " + ex.Message, w);
                }
            }
        }

EDIT: Pic of htm file added to that directory from within browser. enter image description here



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE
Share:

No comments:

Recent