2011-05-20 134 views
2

尝试连接到CRM 2011 Web服务时发生意外错误。这里的背景:CRM 2011 SecurityNewiationException尝试访问Web服务

连接字符串(敏感信息已删除):"ServiceUri=https://crmdomain.com/OrgName/XRMServices/2011/Organization.svc; Url=https://crmdomain.com/OrgName; Username=appusername; Password=hidden"/>

创建连接如下:

  1. 解析康恩串入CRMConnection:var conn = Microsoft.Xrm.Client.CrmConnection.Parse(connString);(在这一点上,属性在CrmConnection对象外观正确,包括ClientCredentials)
  2. 创建组织代理:var orgProxy = new OrganizationServiceProxy(conn.ServiceUri, conn.HomeRealmUri, conn.ClientCredentials, conn.DeviceCredentials);
  3. 创建数据上下文:var context = new MyContext(orgProxy);

此时,从context检索的任何数据时,会出现以下WCF异常:

System.ServiceModel.Security.SecurityNegotiationException发生 消息= 的呼叫者未被该服务认证。 源= mscorlib程序 堆栈跟踪: 服务器堆栈跟踪: 在System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(时间跨度超时) 在System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(时间跨度超时) 在System.ServiceModel .Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超时)

...等等。

The InnerException显示IsSenderFault=TrueIsPredefinedFault=True

这是怎么回事?

+0

如果您使用ServerConnection助手类来构建连接字符串,这仍会失败吗? – Josh 2011-05-20 16:34:28

回答

0

您可能想通过使用CRM跟踪来缩小CRM中的确切错误。您可以使用dedicated tool激活CRM跟踪,并搜索该跟踪以获取有关异常来源的更多详细信息。请注意,跟踪文件速度非常快,因此仅在web服务调用期间跟踪才是合理的。

0

我找到了解决方案。首先,请下载CRM SDK的发布RTW 2011年

代码连接将是:

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; 
    } 
} 

,在这里你去...

干杯!享受编码。