尝试连接到CRM 2011 Web服务时出现意外错误。这是背景:
连接字符串(已删除敏感信息):"ServiceUri=https://crmdomain.com/OrgName/XRMServices/2011/Organization.svc; Url=https://crmdomain.com/OrgName; Username=appusername; Password=hidden"/>
按如下方式创建连接:
var conn = Microsoft.Xrm.Client.CrmConnection.Parse(connString);
(此时,CrmConnection
对象中的属性看起来正确,包括ClientCredentials)var orgProxy = new OrganizationServiceProxy(conn.ServiceUri, conn.HomeRealmUri, conn.ClientCredentials, conn.DeviceCredentials);
var context = new MyContext(orgProxy);
此时,从context
检索任何数据时,会发生以下WCF异常:
发生了System.ServiceModel.Security.SecurityNegotiationException Message = 该服务未对呼叫者进行身份验证。 来源= mscorlib程序 堆栈跟踪: 服务器堆栈跟踪: 在System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(TimeSpan超时) 在System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan超时) 在System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
......等等。
InnerException 显示IsSenderFault=True
和IsPredefinedFault=True
。
这里发生了什么?
答案 0 :(得分:0)
您可能希望使用CRM跟踪缩小CRM中的确切错误。您可以使用dedicated tool激活CRM跟踪并搜索它以获取有关异常来源的更多详细信息。请注意,跟踪文件非常快,因此仅在Web服务调用期间进行跟踪是合理的。
答案 1 :(得分:0)
我找到了解决方案。首先,请下载CRM SDK 2011的RTW版本。
连接代码将是:
public static IOrganizationService Service()
{
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential.UserName ="<username>";
Credentials.Windows.ClientCredential.Password ="<password>";
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://<server name>/<organization name>/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
return service;
}
}
在这里你去......
干杯!享受编码。