Wcf CRM 2016 api未经授权访问
我写这段代码是为了连接到CRM on premise 2016并检索一些数据Wcf CRM 2016 api未经授权访问,wcf,dynamics-crm,crm,Wcf,Dynamics Crm,Crm,我写这段代码是为了连接到CRM on premise 2016并检索一些数据 string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc"; string strUserName = "{your domain username}"; string strPassword = "{your domain password}";
string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc";
string strUserName = "{your domain username}";
string strPassword = "{your domain password}";
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
}
// Get the ID's of the current user and business unit.
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
给你
var credentials = new NetworkCredential("username", "password?", "domain");
var client = new HttpClient(new HttpClientHandler() { Credentials = credentials })
{
BaseAddress = new Uri("https://xxxtestenv.elluciancrmrecruit.com/api/data/v8.0/")
};
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.GetAsync("datatel_events?$orderby=datatel_eventname").Result;
if (response.IsSuccessStatusCode)
{
var yourcustomobjects = response.Content.ReadAsStringAsync();
}
string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc";
string strUserName = "{your domain username}";
string strPassword = "{your domain password}";
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
}
// Get the ID's of the current user and business unit.
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
但是我得到了这个错误
string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc";
string strUserName = "{your domain username}";
string strPassword = "{your domain password}";
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
}
// Get the ID's of the current user and business unit.
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
{
需求ID:b685b007-199b-4a4a-85cc-3a29684e5588
日期:2016年9月22日星期四19:27:35 GMT
服务器:Microsoft IIS/8.5
WWW:协商
WWW:NTLM
X-Powered-By:ASP.NET
连接:保持活力
内容长度:49
内容类型:文本/纯文本
}}System.Net.Http.HttpResponseMessage
string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc";
string strUserName = "{your domain username}";
string strPassword = "{your domain password}";
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
}
// Get the ID's of the current user and business unit.
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
有什么建议吗?尝试使用以下代码连接到MS CRM内部部署
string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc";
string strUserName = "{your domain username}";
string strPassword = "{your domain password}";
var organizationUriIFD = new Uri(strOrganizationUri);
var credentials = new ClientCredentials();
credentials.UserName.UserName = strUserName;
credentials.UserName.Password = strPassword;
IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD);
IOrganizationService service;
using (var serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
service = serviceProxy;
}
// Get the ID's of the current user and business unit.
var who = new WhoAmIRequest();
//retreive user data from the server.
var whoResponse = (WhoAmIResponse)service.Execute(who);
string strOrganizationUri=“https://{your domain}/XRMServices/2011/Organization.svc”;
字符串strUserName=“{您的域名}”;
字符串strPassword=“{您的域密码}”;
var OrganizationUriFd=新Uri(strOrganizationUri);
var credentials=new ClientCredentials();
credentials.UserName.UserName=strUserName;
credentials.UserName.Password=strPassword;
IServiceConfiguration config=ServiceConfigurationFactory.CreateConfiguration(OrganizationUriFd);
组织服务;
使用(var serviceProxy=neworganizationserviceproxy(配置,凭据))
{
//此语句是启用早期绑定类型支持所必需的。
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(新的ProxyTypesBehavior());
服务=服务代理;
}
//获取当前用户和业务部门的ID。
var who=新WhoAmIRequest();
//从服务器检索用户数据。
var whoResponse=(WhoAmIResponse)service.Execute(who);
是否启用了IFD?是的,我们可以从任何地方访问它。调试代码时,我发现httpclient将链接重定向到另一个链接,我们使用该链接登录到crm。你觉得这正常吗?