我需要使用公开的动态CRM数据服务端点来从其中一种方法获取数据。 服务(Microsoft)帐户可以访问此服务。 我试过使用此处提供的示例代码对发现服务和组织服务进行身份验证[https://msdn.microsoft.com/en-us/library/hh675404.aspx]并且成功。但是我无法使用相同的身份验证来访问数据服务,因为无论如何我都无法将数据服务与其他两个服务关联起来。使用网络凭证进行基本身份验证不起作用。无法在访问动态CRM Online Web服务时进行身份验证
我已经下载了CSDL公开的内容,并将其作为服务引用添加到我的项目中,该项目创建了一个从DataServiceContext扩展的Web服务类。我试图使用LinQ查询检索其中一种方法的数据。它returs以下错误:“响应有效载荷是不是一个有效的响应负载请确保最高级别的元素是一个有效的Atom或JSON元素或属于‘http://schemas.microsoft.com/ado/2007/08/dataservices’命名空间。”
在捕捉使用小提琴时,我意识到,在打数据服务的URL它被重定向到登录页面'login.microsoftonline.com/'
任何人都可以提出一种方法来验证用户访问Data Serivce吗?
添加代码:
//<snippetAuthenticateWithNoHelp1>
IServiceManagement<IDiscoveryService> serviceManagement =
ServiceConfigurationFactory.CreateManagement<IDiscoveryService>(
new Uri(_discoveryServiceAddress));
AuthenticationProviderType endpointType = serviceManagement.AuthenticationType;
// Set the credentials.
AuthenticationCredentials authCredentials = GetCredentials(serviceManagement, endpointType);
String organizationUri = String.Empty;
// Get the discovery service proxy.
using (DiscoveryServiceProxy discoveryProxy =
GetProxy<IDiscoveryService, DiscoveryServiceProxy>(serviceManagement, authCredentials))
{
// Obtain organization information from the Discovery service.
if (discoveryProxy != null)
{
// Obtain information about the organizations that the system user belongs to.
OrganizationDetailCollection orgs = DiscoverOrganizations(discoveryProxy);
// Obtains the Web address (Uri) of the target organization.
organizationUri = FindOrganization(_organizationUniqueName,
orgs.ToArray()).Endpoints[EndpointType.OrganizationService];
}
}
//</snippetAuthenticateWithNoHelp1>
if (!String.IsNullOrWhiteSpace(organizationUri))
{
//<snippetAuthenticateWithNoHelp3>
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(
new Uri(organizationUri));
// Set the credentials.
AuthenticationCredentials credentials = GetCredentials(orgServiceManagement, endpointType);
// Get the organization service proxy.
using (OrganizationServiceProxy organizationProxy =
GetProxy<IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, credentials))
{
// This statement is required to enable early-bound type support.
organizationProxy.EnableProxyTypes();
// Now make an SDK call with the organization service proxy.
// Display information about the logged on user.
Guid userid = ((WhoAmIResponse)organizationProxy.Execute(
new WhoAmIRequest())).UserId;
SystemUser systemUser = organizationProxy.Retrieve("systemuser", userid,
new ColumnSet(new string[] { "firstname", "lastname" })).ToEntity<SystemUser>();
Console.WriteLine("Logged on user is {0} {1}.",
systemUser.FirstName, systemUser.LastName);
Uri x = new Uri("https://<MyOrgainzationName>.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/");
MyOrgainzationContext saContext = new MyOrgainzationContext(x);
NetworkCredential nc = new NetworkCredential();
nc.UserName = "*****@microsoft.com";
nc.Password = "********";
saContext.Credentials = nc;
var query_where3 = from c in saContext.new_productSet
select new
{
ProductStatus = c.new_ProductStatus,
LineofBusiness = c.new_LineofBusiness
};
var temp = saContext.Entities;
foreach (var c in query_where3)
{
System.Console.WriteLine("ProductStatus: " +
c.ProductStatus +
"\t\t\t" +
"LineofBusiness: " +
c.LineofBusiness);
}
}
//</snippetAuthenticateWithNoHelp3>
}
MyOrganizationContext是添加在服务端点
谷歌“动态crm简化连接” –
你的意思是你试图从xRM之外访问OData端点吗?如果你发布你的代码会有帮助。 –
是James通过控制台应用程序。它有可能吗? – 1621pooja