0

我有一个连接到 Dynamics CRM 以执行定期数据加载的 Windows 服务。

发生此错误:
在配置的安全令牌服务上找不到身份验证端点用户名!

该服务以前可以工作,但代码一直在更改,并且可能在 CRM 服务器或运行 Windows 服务的服务器上发生了更改。

如果该应用程序从作为 Windows 服务失败的同一台计算机作为控制台应用程序启动,则该应用程序将运行。

该应用程序作为服务和控制台应用程序在我的开发机器上运行。

public class CRMSync
{
    /* There are more fields and methods that are not pertinent */
    /* Called by CRMAUX.OnStart when it is time to start the service */
    public async void Start()
    {
        this.Test();
        var freq = 0;
        ConfigurationManager.RefreshSection("appSettings");
        var parse = int.TryParse(ConfigurationManager.AppSettings["Frequency"], out freq);
        await System.Threading.Tasks.Task.Delay((parse) ? freq * 1000 * 60 : 15000 * 60); // 15 minutes default or user defined
        Start();
    }
    /* Do something to test */
    private void Test()
    {
        Connect(); // Connect to CRM and instantiate service and linq (the service context)
        Log(linq.sbuys_scriptsSet.FirstOrDefault().sbuys_Number); // Write to the Event Viewer
        service.Dispose(); // Dispose the OrganizationServiceProxy
    }
}

编辑

这是连接方法

    /* Tries to connect to CRM and return false if failure - credentials arguments */
    private bool Connect(string username, string password, string uri)
    {
        try
        {
            var cred = new ClientCredentials();
            cred.UserName.UserName = username;
            cred.UserName.Password = password;
            service = new OrganizationServiceProxy(new Uri(uri), null, cred, null);
            service.EnableProxyTypes(); // this has to happen to allow LINQ early bound queries
            linq = new Context(service);
            var who = new Microsoft.Crm.Sdk.Messages.WhoAmIRequest(); // used to test the connection
            var whoResponse = (Microsoft.Crm.Sdk.Messages.WhoAmIResponse)service.Execute(who); // this fails if not connected       
        }
        catch (Exception e)
        {
            Log(e.Message);
            return false;
        }
        return true;
    }
4

0 回答 0