为什么连接到 Dynamics CRM 元数据服务时会出现 401 错误?
我连接到 CRM 的目的是检索选项列表值的列表。 在我的开发机器上,我使用自己的登录名工作,一切正常。 在测试服务器上,代码在 NETWORK SERVICE 帐户下执行。 当它连接到 CRM Web 服务时,一切都很棒。 当它连接到元数据服务时,我收到 401 未经授权的消息。
这是我第一次使用元数据服务,所以我希望有人能告诉我为什么会收到错误。 使用下面的代码配置连接,当您尝试检索选项列表数据时会发生失败。
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = config.AppSettings.Settings["CrmTargetOrganisation"].Value;
token.AuthenticationType = 0;
MetadataService service = new MetadataService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = config.AppSettings.Settings["CrmMetadataServiceUrl"].Value;
service.CrmAuthenticationTokenValue = token;
service.UnsafeAuthenticatedConnectionSharing = true;
I am connecting to CRM with the intention of retrieving a list of picklist values. On my development machine I am working under my own login name and all works fine. On the test server, the code executes under the NETWORK SERVICE account. When it connects to the CRM web service everything is great. When it connects to the metadata service I get 401 Unauthorised messages.
This is the first time I have used the metadata service so I am hoping someone can tell me why I get the error. The connection is configured using the code below and the failure happens when you try to retrieve the picklist data.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = config.AppSettings.Settings["CrmTargetOrganisation"].Value;
token.AuthenticationType = 0;
MetadataService service = new MetadataService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = config.AppSettings.Settings["CrmMetadataServiceUrl"].Value;
service.CrmAuthenticationTokenValue = token;
service.UnsafeAuthenticatedConnectionSharing = true;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这可能是 Kerberos/委派问题,以确保尝试将 DefaultCredentials 替换为
new System.Security.Net.NetworkCredentials("用户名","密码","域");
看看这是否仍然给你一个 401。
这是我通常尝试查看它是否与 kerbos/安全相关的快速方法。
我需要更多有关您的环境的信息才能做出其他明智的评论。
希望能帮助到你。
I suspect it might be a Kerberos / delegation issue, to make sure it is try replacing DefaultCredentials with
new System.Security.Net.NetworkCredentials("username","password","domain");
See if that still gives you a 401.
This is the quick way I normally try to see if it is kerbos/security related.
I need a bit more information about your environment to make any other intelligent comments.
Hope it helps.
就我而言(是的,我们仍然使用 CRM 4),IIS 中的网站未绑定到用于访问端口 5555 上的元数据服务的主机名。
In my case (yes, we still use CRM 4), the website in IIS wasn't bound to the hostname being used to access the metadata service on port 5555.