1

既存の asp.net イントラネット アプリケーションに Web サービスを追加しました。目的は、同じドメイン上の他のイントラネット アプリケーションに機能を公開することです。

イントラネット アプリケーションは Windows 認証を使用します。Windows 認証を使用するように Web サービスをセットアップするにはどうすればよいですか?

4

2 に答える 2

0
Client.localhost.Service1 service = new Client.localhost.Service1();
   service.Credentials = new System.Net.NetworkCredential("username", "pass", "");
于 2012-04-04T16:17:04.603 に答える
0

Windows 認証を使用するように Web サービスを設定するのは簡単です。IIS で認証モードを変更するだけです。

そのサービスとの通信は別の問題です。まず、消費するアプリケーションの Web 構成でサービス参照を適切に設定する必要があります。以下のセキュリティ セクションは、これを機能させる上で最も重要な部分です。

<system.serviceModel>
<bindings>
<basicHttpBinding>
    <binding name="ServiceSoap" 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="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://yourservice.com/Service.asmx"
    binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
    contract="ServiceClient.IServiceSoap" name="ServiceSoap" />
</client>

次に、使用を開始する前に、クライアント オブジェクトのWindows資格情報を設定する必要があります。

var credentials = ServiceSoapClient.ClientCredentials;
credentials.Windows.ClientCredential.Domain = "domain";
credentials.Windows.ClientCredential.UserName = "user";
credentials.Windows.ClientCredential.Password = "pwd";
credentials.Windows.AllowNtlm = true;
于 2012-04-04T16:37:25.133 に答える