1

我正在尝试为 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();
        }
    }
}

网页配置

<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 设置?

4

0 回答 0