调用WebGet方法的Windows服务返回400错误

时间:2017-08-31 16:52:08

标签: c#

我有一个运行c#方法的服务,以指定的时间间隔将数据库与活动目录同步。此代码在测试环境中工作,现在将其放在不同的服务器上,它返回以下消息:

  

服务器在处理请求时遇到错误。请看看   服务帮助页面,用于构建对服务的有效请求。

帮助页面如下所示:

enter image description here

但是“SyncActiveDirectory”URI给了我这个错误:

enter image description here

这是一个新服务器。也许我错过了需要安装的东西或IIS中的设置?任何帮助将不胜感激。

编辑: 以下是调用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()");

        }

以下是调用的方法:

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);
                }
            }
        }

编辑: 添加到该目录的htm文件的图片。 enter image description here

编辑: 如果这有助于Chrome Developer Tools标题: enter image description here

0 个答案:

没有答案