简体   繁体   English

Web服务无法连接Sharepoint站点“无法连接远程服务器”

[英]Web service unable to connect Sharepoint site “unable to connect remote server”

I have written the code as below: 我写了如下代码:

  try
    {


        ClientContext context = new ClientContext("https://test.com/");
        System.Net.ServicePointManager.ServerCertificateValidationCallback =
            ((sender, certificate, chain, sslPolicyErrors) => true);

        string strUserName = @"abc";
        string strPassword = "pwd";
        var credentials = new NetworkCredential(strUserName, strPassword);
        Web web = context.Web;
        context.Load(web, w => w.Title);
        context.Credentials = credentials;
        context.ExecuteQuery();


        // Now, the web's properties are available and we could display 
        // web properties, such as title. 
        System.Console.WriteLine("Web Title");
        System.Console.WriteLine(web.Title);
    }
    catch (Exception ex)
    {
    }

It's working fine in the console application, but same code is not working when I am calling from a web service. 在控制台应用程序中它可以正常工作,但是当我从Web服务中调用时,相同的代码不起作用。

Given our discussion; 考虑到我们的讨论; the problem is likely that the account that your IIS app pool is running under is not authorized to access the Sharepoint site. 该问题很可能是您的IIS应用程序池所运行的帐户无权访问Sharepoint站点。 You need the app pool account to have access in AD in order for your code to work. 您需要应用程序池帐户在AD中具有访问权限才能使代码正常工作。 You'll need to do one of the following; 您需要执行以下操作之一;

Get the App pool account granted AD rights to Sharepoint. 获取授予Sharepoint AD权限的应用程序池帐户。 This is less likely as IIS 7 and above use "odd accounts" by default for app pools. 由于IIS 7及更高版本默认对应用程序池使用“奇数帐户”,因此这种可能性较小。

More likely is you'll need to change the account your app pool is running under to one that has the appropriate AD rights. 您更有可能需要将您的应用程序池所运行的帐户更改为具有适当AD权限的帐户。 In most companies I've worked for there is a "Service Account" or "Automated Account" used for this purpose. 在我工作过的大多数公司中,都有用于此目的的“服务帐户”或“自动帐户”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM