我正在尝试访问 WCF 服务(MS CRM 2011)并收到上述错误。如果我使用 Cassini 或 IIS Express 从 VS2010 调试器运行我的示例程序,它会很好地工作。没有身份验证错误。
但是,如果我将站点发布到本地 IIS 7.5(运行 Windows 7 64 位),我会在获取 CRM UserId (WhoAmIResponse) 的行上收到错误消息。
我打开 Fiddler 来比较在调试器下运行和在 IIS 下运行之间的请求。在 IIS 下运行的站点上,请求甚至从未遇到过,因此在到达那一步之前它必须失败。
发布到 IIS 的站点将其 web.config 设置为...
<authentication mode="Windows">
</authentication>
<identity impersonate="true"/>
该站点在预装的 ASP.NET v4.0 应用程序池、集成管道模式、ApplicationPoolIdentity 帐户下运行。
这是我的代码...
public class DemoController : Controller
{
public ActionResult Index()
{
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var _serviceProxy = new OrganizationServiceProxy(new Uri("http://svr-rex2011-dev/TimeEntry/XRMServices/2011/Organization.svc"),
null,
credentials,
null);
// This statement is required to enable early-bound type support.
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
IOrganizationService service = (IOrganizationService)_serviceProxy;
// Display information about the logged on user.
Guid userid = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;
SystemUser systemUser = (SystemUser)service.Retrieve("systemuser", userid,
new ColumnSet(new string[] { "firstname", "lastname" }));
// Retrieve the version of Microsoft Dynamics CRM.
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
RetrieveVersionResponse versionResponse =
(RetrieveVersionResponse)service.Execute(versionRequest);
ViewBag.FirstName = systemUser.FirstName;
ViewBag.LastName = systemUser.LastName;
ViewBag.Version = versionResponse.Version;
return View();
}
}
有任何想法吗?非常感激!!!