我已经设置了我的IIS WCF Web服务以使用Windows身份验证(通过https),并且在访问WSDL时,我从服务器获得了进行身份验证的请求,然后该请求正常运行。所以一切都很好。
但是,我无法弄清楚如何传递当前用户的Windows凭据,我不断收到主题中详述的错误。
这是服务器web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsBindingTest">
<security mode="Transport">
<message negotiateServiceCredential="true" clientCredentialType="Windows"/>
<transport clientCredentialType="Windows"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="wsBindingTest" />
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
这是客户:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="BasicHttpBinding_ITRIMService">
<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://servername.net/TRIMDev/TRIMService.svc"
binding="wsHttpBinding" bindingConfiguration="BasicHttpBinding_ITRIMService"
contract="Service.ITRIMService" name="BasicHttpBinding_ITRIMService">
<identity>
<servicePrincipalName value="host/servername.net" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
这是最终创建频道的代码:
ConfigurationChannelFactory<ITRIMService> channelFactory = new ConfigurationChannelFactory<ITRIMService>("BasicHttpBinding_ITRIMService", config, null);
var channel = channelFactory.CreateChannel();
我尝试将以下内容添加到客户端配置中,没有运气,希望无需在客户端编写任何代码即可完成:
<system.web>
<identity impersonate="true"/>
<authentication mode="Windows" />
</system.web>
任何帮助都会非常感激,因为我不知道为什么它不起作用。