我正在尝试从 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.
发布评论
评论(3)
您的代码不正确。您正在混合 元数据服务 和CRM 服务。
要与 CRM 数据交互,您应该使用 客户关系管理服务。 发现服务类似于CRM 部署的黄页。
这将创建与 CRM 服务的连接。
要检索数据,您可以使用
RetrieveMultiple
CrmService 的方法。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.
This creates the connection to the CRM Service.
To retrieve data you could use the
RetrieveMultiple
method of the CrmService.这绝对不是您检索实体记录所需的方式。 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?
如果您在插件中或在无法访问底层 SQL 数据库的 CRM Online 版本中工作,那么 ckeller 的上述答案很好。如果这是在本地安装中,并且您可以通过 SQL Server 访问 CRM 表,则直接查询 SQL 表或视图以读取实体信息通常会更快、更直接。您只需要执行以下 SQL 查询并使用 SQL 数据读取器或数据表读出结果 -
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 -