我已将Web服务添加到现有的asp.net Intranet应用程序中。目的是向同一域上的其他Intranet应用程序公开功能。
Intranet应用程序使用Windows身份验证。如何设置Web服务以使用Windows身份验证?
答案 0 :(得分:0)
Client.localhost.Service1 service = new Client.localhost.Service1();
service.Credentials = new System.Net.NetworkCredential("username", "pass", "");
答案 1 :(得分:0)
设置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;