Dynamics CRM 中未经授权

发布于 2024-11-05 05:27:30 字数 1033 浏览 3 评论 0 原文

我正在尝试从 CRM 4.0 检索联系人列表,但在身份验证时遇到问题。根据我的阅读,列出所有 clinet 的方法是解析从 ExportAllXmlRequest 返回的 XML

问题是,当我浏览到 http://crmserver/MSCRMServices/2007/spla/CRMDiscoveryService.asmx,我得到一个401.2 未经授权且不提示进行身份验证。如果我通过 Visual Studio 添加 Web 引用,则会收到密码提示,该提示不接受我的凭据。我还尝试使用以下代码在代码中进行身份验证,但都不起作用。服务器上同时启用了 Windows 身份验证和匿名身份验证。

CrmService svc = new CrmService();
// this doesn't work
svc.UseDefaultCredentials = true;

// this doesn't work either
svc.Credentials = new NetworkCredential("myuser", "password", "mydomain");
svc.Credentials= System.Net.CredentialCache.DefaultCredentials;
ExportAllXmlRequest request = new ExportAllXmlRequest();

ExportAllXmlResponse response = (ExportAllXmlResponse)svc.Execute(request);
string resp=string.Empty;
using (StreamReader reader = new StreamReader(response.ExportXml)) {
    resp = reader.ReadToEnd();
}
return resp;

是否有 1) 一种更简单的方法来列出 CRM 中的联系人,2) 我可以做些什么来解决此身份验证问题。

I'm trying to retrieve a list of contacts from CRM 4.0 but I'm having problems authenticating. From what I've read, the method of listing all clinets is to parse the XML returned from an ExportAllXmlRequest

The problem is, when I browse to http://crmserver/MSCRMServices/2007/spla/CRMDiscoveryService.asmx, I get a 401.2 unauthorized and no prompt to authenticate. If I add the web reference via visual studio, I get a password prompt which doesn't accept my credentials. I've also tried authenticating in code with the following, but neither work. Windows Authentication and Anonymous Authentication are both enabled on the server.

CrmService svc = new CrmService();
// this doesn't work
svc.UseDefaultCredentials = true;

// this doesn't work either
svc.Credentials = new NetworkCredential("myuser", "password", "mydomain");
svc.Credentials= System.Net.CredentialCache.DefaultCredentials;
ExportAllXmlRequest request = new ExportAllXmlRequest();

ExportAllXmlResponse response = (ExportAllXmlResponse)svc.Execute(request);
string resp=string.Empty;
using (StreamReader reader = new StreamReader(response.ExportXml)) {
    resp = reader.ReadToEnd();
}
return resp;

Is there 1) An easier method of listing contacts from CRM and 2) something I can do to fix this authentication issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我还不会笑 2024-11-12 05:27:30

您的代码不正确。您正在混合 元数据服务CRM 服务

要与 CRM 数据交互,您应该使用 客户关系管理服务发现服务类似于CRM 部署的黄页。

// Set up the CRM Service.
var token = new CrmAuthenticationToken();
token.AuthenticationType = 0; 
token.OrganizationName = "{yourorgname}";

var service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

这将创建与 CRM 服务的连接。
要检索数据,您可以使用 RetrieveMultiple CrmService 的方法。

 // Create the QueryExpression object.
 var query = new QueryExpression();

 // Set the properties of the QueryExpression object.
 query.EntityName = EntityName.contact.ToString();
 query.ColumnSet = new AllColumns();

 // Retrieve the contacts.
 BusinessEntityCollection contacts = service.RetrieveMultiple(query);

Your code is not correct. You are mixing the Metadata Service and the CRM Service.

For interacting with the CRM data, you should use the CRM Service. The Discovery Service is something like the yellow pages for the CRM deployment.

// Set up the CRM Service.
var token = new CrmAuthenticationToken();
token.AuthenticationType = 0; 
token.OrganizationName = "{yourorgname}";

var service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

This creates the connection to the CRM Service.
To retrieve data you could use the RetrieveMultiple method of the CrmService.

 // Create the QueryExpression object.
 var query = new QueryExpression();

 // Set the properties of the QueryExpression object.
 query.EntityName = EntityName.contact.ToString();
 query.ColumnSet = new AllColumns();

 // Retrieve the contacts.
 BusinessEntityCollection contacts = service.RetrieveMultiple(query);
浅暮の光 2024-11-12 05:27:30

这绝对不是您检索实体记录所需的方式。 ExportAllXmlRequest 将提取您的 CRM 环境的自定义信息,但不会有实际记录。您将需要 RetrieveMultipleRequest (sdk 链接:http://msdn.microsoft.com /en-us/library/bb929303.aspx)。

关于身份验证问题,您的 CRM 站点是否在 IE 中的受信任站点或 Intranet 站点列表中?

This is definitely not the way you need to retrieve entity records. An ExportAllXmlRequest will pull the customizations information for your CRM environment, but will have no actual records. You'll want the RetrieveMultipleRequest (sdk link: http://msdn.microsoft.com/en-us/library/bb929303.aspx).

As to the authentication issue, is your CRM site in your list of trusted or intranet sites in IE?

橘虞初梦 2024-11-12 05:27:30

如果您在插件中或在无法访问底层 SQL 数据库的 CRM Online 版本中工作,那么 ckeller 的上述答案很好。如果这是在本地安装中,并且您可以通过 SQL Server 访问 CRM 表,则直接查询 SQL 表或视图以读取实体信息通常会更快、更直接。您只需要执行以下 SQL 查询并使用 SQL 数据读取器或数据表读出结果 -

SELECT * FROM OrgName_MSCRM.dbo.FilteredContact

ckeller's answer above is good if you are working within a plugin or in the CRM Online version where you don't have access to the underlying SQL database. If this is in an on-premise installation and you have SQL server access to the CRM tables, it is often faster and more straightforward to query the SQL tables or views directly to read entity information. You would just need to execute the following SQL query and read out the results with a SQL data reader or datatable -

SELECT * FROM OrgName_MSCRM.dbo.FilteredContact
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文