Project Server への BasicHttpBinding を作成しようとしています。しかし、401エラーが発生し続けます。
インフラストラクチャー:
サーバー A (IP: 192.168.123.10) は IIS 7.5 で、サーバー B (IP: 192.168.123.20) は SharePoint (Project Server 2010) です。どちらもドメイン内にあります。次のテスト Web アプリケーション (MVC) は、サーバー A で公開されています。
HomeController.cs:
using System;
using System.Security.Principal;
using System.ServiceModel;
using System.Net;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
const int MAXSIZE = 500000000;
BasicHttpBinding binding = null;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
String pwaUrl = "http://192.168.123.20:24010";
const string svcRouter = "/_vti_bin/PSI/ProjectServer.svc";
// Create a binding for HTTP.
binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.Name = "basicHttpConf";
binding.SendTimeout = TimeSpan.MaxValue;
binding.MaxReceivedMessageSize = MAXSIZE;
binding.ReaderQuotas.MaxNameTableCharCount = MAXSIZE;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
// The endpoint address is the ProjectServer.svc router for all public PSI calls.
EndpointAddress address = new EndpointAddress(pwaUrl + svcRouter);
SvcResource.ResourceClient _resourceClient;
NetworkCredential credentials = CredentialCache.DefaultNetworkCredentials;
_resourceClient = new SvcResource.ResourceClient(binding, address);
_resourceClient.ClientCredentials.Windows.ClientCredential = credentials;
_resourceClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
ViewBag.ThreadUser = System.Threading.Thread.CurrentPrincipal.Identity.Name;
ViewBag.TESTUSER = _resourceClient.GetCurrentUserUid();
return View();
}
public ActionResult About()
{
return View();
}
}
}
Web.config
<authentication mode="Windows" />
<identity impersonate="true"/>
<authorization>
<deny users="?" />
</authorization>
関数で、ViewBag.TESTUSER = _resourceClient.GetCurrentUserUid();
説明できない401エラーが発生しました。
エラーメッセージ:
[WebException: Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert.]
System.Net.HttpWebRequest.GetResponse() +7866004
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +99
[MessageSecurityException: Die HTTP-Anforderung ist beim Clientauthentifizierungsschema "Ntlm" nicht autorisiert. Vom Server wurde der Authentifizierungsheader "NTLM" empfangen.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4729427
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
SvcResource.Resource.GetCurrentUserUid() +0
SvcResource.ResourceClient.GetCurrentUserUid() +52
なぜこれが起こっているのか知っていますか?Project Server 2010 の設定を変更する必要がありますか? それとも Active Directory の設定を変更する必要がありますか?