49

これに似た SO に関する質問がたくさんあることは知っていますが、この特定の問題に関する質問は見つかりませんでした。

最初にいくつかのポイント:

  • 私は、Sharepoint サーバーを制御できません。IIS 設定を微調整できません。
  • IIS サーバーのバージョンは IIS 7.0 だと思います。
  • Sharepoint Server は NTLM 経由のリクエストを予期しています。
  • Sharepoint Server は、クライアント コンピューターと同じドメインにあります。
  • .NET Framework 3.5、Visual Studio 2008 を使用しています

Sharepoint Web サービスを使用して SharePoint データを操作する単純なコンソール アプリを作成しようとしています。サービス参照を追加しました。以下は app.config です。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Transport">
                    <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://subdomain.companysite.com/subsite/_vti_bin/Lists.asmx"
            binding="basicHttpBinding" bindingConfiguration="ListsSoap"
            contract="ServiceReference1.ListsSoap" name="ListsSoap" />
    </client>
</system.serviceModel>

これは私のコードです:

static void Main(string[] args)
{
    using (var client = new ListsSoapClient())
    {
        client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
        client.GetListCollection();
    }
}

GetListCollection() を呼び出すと、次のMessageSecurityExceptionがスローされます。

The HTTP request is unauthorized with client authentication scheme 'Ntlm'.
The authentication header received from the server was 'NTLM'.

内部 WebException の場合:

"The remote server returned an error: (401) Unauthorized."

さまざまなバインディングとさまざまなコードの微調整を試みて、適切に認証しようとしましたが、役に立ちませんでした。以下にそれらをリストします。


次の手順を試しました。

クライアントを作成する前にネイティブの Win32 Impersonator を使用する

using (new Impersonator.Impersonator("username", "password", "domain"))
using (var client = new ListsSoapClient())
{
    client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("dpincas", "password", "domain");
    client.GetListCollection();
}

これにより、同じエラー メッセージが生成されました。


クライアント資格情報の TokenImpersonationLevel の設定

using (var client = new ListsSoapClient())
{
    client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
    client.GetListCollection();
}

これにより、同じエラー メッセージが生成されました。


セキュリティ モードの使用 = TransportCredentialOnly

<security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" />
</security>

これにより、別のエラー メッセージが表示されました。

The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via

ただし、https を使用する必要があるため、URI スキームを変更できません。


覚えていない他の組み合わせをいくつか試しましたが、それらを投稿します。私は本当にここで機知に富んでいます。Google には「Kerberos に切り替える」というリンクがたくさんありますが、私のサーバーは「ネゴシエート」ではなく NTLM のみを受け入れているようです (Kerberos を探しているかのように)。残念ながらそれはオプションではありません。 .

皆さん、何か助けはありますか?

4

10 に答える 10

40

ビジュアル スタジオ 2005

  1. Visual Studio で新しいコンソール アプリケーション プロジェクトを作成する
  2. Lists.asmx Web サービスに「Web 参照」を追加します。
    • URL はおそらく次のようになります。http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx
    • Web 参照に次の名前を付けました。ListsWebService
  3. program.cs にコードを記述します (ここに問題のリストがあります)。

これがコードです。

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace WebServicesConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ListsWebService.Lists listsWebSvc = new WebServicesConsoleApp.ListsWebService.Lists();
                listsWebSvc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                listsWebSvc.Url = "http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx";
                XmlNode node = listsWebSvc.GetList("Issues");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

ビジュアル スタジオ 2008

  1. Visual Studio で新しいコンソール アプリケーション プロジェクトを作成する
  2. 参照を右クリックしてサービス参照を追加
  3. サーバー上の Lists.asmx サービスへの URL を入力します。
    • 元:http://servername/sites/SiteCollection/SubSite/_vti_bin/Lists.asmx
  4. [進む] をクリックします
  5. [OK] をクリックします。
  6. 次のコード変更を行います。

app.config ファイルを次のように変更します。

<security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None"
        realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

に:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm"/>
</security>

program.cs ファイルを変更し、次のコードを Main 関数に追加します。

ListsSoapClient client = new ListsSoapClient();
client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
XmlElement listCollection = client.GetListCollection();

using ステートメントを追加します。

using [your app name].ServiceReference1;
using System.Xml;

参照: http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrifying-list-items-from-a-sharepoint-list

于 2010-04-09T18:31:14.463 に答える
8

何度も試行錯誤を繰り返した後、サーバーの担当者と話す機会を待っていた停滞期が続きましたが、ようやく問題について話し合う機会があり、Sharepoint 認証を切り替えてもよろしいでしょうかと尋ねました。ケルベロスに。

驚いたことに、彼らはこれは問題にならないと言い、実際には簡単に実行できました。彼らは Kerberosを有効にし、app.config を次のように変更しました。

<security mode="Transport">
    <transport clientCredentialType="Windows" />
</security>

参考までに、私の app.config の完全な serviceModel エントリは次のようになります。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="TestServerReference" closeTimeout="00:01:00" openTimeout="00:01:00"
             receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
             bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2000000" maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                 maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Transport">
                    <transport clientCredentialType="Windows" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://path/to/site/_vti_bin/Lists.asmx"
         binding="basicHttpBinding" bindingConfiguration="TestServerReference"
         contract="TestServerReference.ListsSoap" name="TestServerReference" />
    </client>
</system.serviceModel>

この後、すべてが魔法のように機能しました。これで (ついに!) Sharepoint Web Services を利用できるようになりました。そのため、Sharepoint Web サービスを NTLM で動作させることができない人がいる場合は、システム管理者に Kerberos に切り替えるよう説得できるかどうかを確認してください。

于 2010-10-15T15:19:01.107 に答える
5

うまくいかなかった多くの回答の後、IISサーバーで匿名アクセスが無効になっている場合の解決策を最終的に見つけました。私たちのサーバーは、Kerberos ではなく Windows 認証を使用しています。これは、このブログ投稿のおかげです。

web.config は変更されていません。

サーバー側では、ISAPI フォルダー内の .SVC ファイルは MultipleBaseAddressBasicHttpBindingServiceHostFactory を使用します。

サービスのクラス属性は次のとおりです。

[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class InvoiceServices : IInvoiceServices
{
...
}

クライアント側では、それを機能させる鍵は http バインディング セキュリティ属性でした。

EndpointAddress endpoint =
  new EndpointAddress(new Uri("http://SharePointserver/_vti_bin/InvoiceServices.svc"));
BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
InvoiceServicesClient myClient = new InvoiceServicesClient(httpBinding, endpoint);
myClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 

(call service)

これがうまくいくことを願っています!

于 2012-02-24T19:01:37.353 に答える
3

私の記憶が正しければ、SharePoint Web サービスを VS2K8 の「サービス リファレンス」として追加する際にいくつか問題がありました。正しく機能させるには、古いスタイルの「Web 参照」として追加する必要があります。

于 2010-07-12T18:46:55.963 に答える
2

私はあなたがするのと同じセットアップを持っています、そしてこれは私にとってうまくいきます。おそらく問題は、モス構成またはネットワークのどこかにあると思います。

あなたは苔があなたのアプリケーションと同じドメインにあると言いました。ユーザー(マシンにログインしている)でサイトにアクセスできる場合...試してみましたか?

client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
于 2010-07-13T13:26:29.813 に答える
2

私は以前にこの問題を抱えていました。

client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

呼び出しを行う前に、wcf プロキシに対してこれを行います。

于 2010-07-18T01:53:49.163 に答える
2

こちらのツールを使用して、Sharepoint サイトに接続してみます。それが機能する場合、問題がコード/構成にあることを確認できます。これで問題がすぐに解決するわけではありませんが、サーバーに問題があることは除外されます。それが機能しないと仮定して、次のことを調査します。

  • あなたのユーザーは本当にサイト上で十分な権限を持っていますか?
  • 干渉するプロキシはありますか? (あなたの設定はプロキシがあるように見えます。バイパスできますか?)

セキュリティ モードTransportを使用しても問題はないと思いますが、についてはよくわかりません。proxyCredentialType="Ntlm"おそらく、これをNoneに設定する必要があります。

于 2010-07-14T16:39:15.083 に答える
2

私は先週まったく同じ問題を抱えていました.1つのサーバーでWCFプログラムが奇妙に動作します.なぜですか?

私にとって、解決策はかなり単純でした。Sharepoint には独自の権限セットがあります。私のクライアントは、Sharepoint の管理パネルから Web サービスへのアクセスを明示的に許可されていないユーザーとしてログオンしようとしました。

ユーザーをSharepointのホワイトリストに追加して強打しました-うまくいきました。

それが問題ではない場合でも、次のことに注意してください。

HTTP 要求は、クライアント認証方式 'Ntlm' では許可されていません。サーバーから受信した認証ヘッダーは「NTLM」でした。

(英語で)単に許可がないことを意味します。あなたのプロトコルはおそらく正しいでしょう - あなたのユーザーには権限がありません。

于 2010-07-13T13:55:49.473 に答える
0

これを試して

<client>
  <endpoint>
    <identity>
      <servicePrincipalName value="" />
    </identity>
  </endpoint>
</client>

ウェブファームで作業しているときにこのエラーが発生したことがあり、これで修正されました。

于 2010-07-13T13:33:12.740 に答える