[英]WCF SecurityNegotiationException by trying remote access
[英]CRM 2011 SecurityNegotiationException trying to access web services
尝试连接到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 = 服务未验证调用方。 Source = mscorlib StackTrace:服务器堆栈跟踪:位于System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(TimeSpan超时)位于System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan超时)位于System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen( TimeSpan超时)
... 等等。
InnerException显示IsSenderFault=True
和IsPredefinedFault=True
。
这里发生了什么?
您可能想通过使用CRM跟踪来缩小CRM中的确切错误。 您可以使用专用工具激活CRM跟踪,并在其中搜索有关异常源的更多详细信息。 请注意,跟踪文件很快变得非常大,因此仅在webservice调用期间进行跟踪是合理的。
我找到了解决方案。 首先,请下载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;
}
}
然后你去...
干杯! 享受编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.