Web Services Web服务- Windows身份验证

ej83mcc0  于 2022-11-15  发布在  Windows
关注(0)|答案(2)|浏览(166)

我已将Web服务添加到现有的asp.net Intranet应用程序中。目的是向同一域中的其他Intranet应用程序公开功能。
Intranet应用程序使用Windows身份验证。如何将Web服务设置为使用Windows身份验证?

7gs2gvoe

7gs2gvoe1#

Client.localhost.Service1 service = new Client.localhost.Service1();
   service.Credentials = new System.Net.NetworkCredential("username", "pass", "");
pokxtpni

pokxtpni2#

将Web服务设置为使用Windows身份验证非常简单。您只需在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;

相关问题