我在使用wcf服务设置TransportWithMessageCredential时遇到问题。
使用wcf配置编辑器,我在服务的web.config和我的可执行文件的app.config中将Mode设置为TransportWithMessageCredential,将transportClientCredentialType设置为Windows。我在erver上安装了一个自签名证书,并配置了IIS来使用它。
当我运行我的测试应用时,收到以下错误: System.InvalidOperationException:未提供用户名。在ClientCredentials中指定用户名。
似乎Windows凭据未传递给wcf服务,当我检查credentialCache.defaultCredentials时,它们为空。关于为什么会这样做以及如何修复它的任何线索和/或提示?提前致谢
活动目录域上的server 2003 / IIS 6.0。
服务的web.config
<service name="Test.DiagnosticService">
<endpoint binding="basicHttpBinding" bindingConfiguration="WindowsTransportCredentialBinding" name="ClientDiagnosticEndpoint" contract="Test.IDiagnostic" />
</service>
<basicHttpBinding>
<binding name="WindowsTransportCredentialBinding" maxBufferSize="524288"
maxReceivedMessageSize="524288">
<readerQuotas maxDepth="128" maxStringContentLength="1048576" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="Windows" />
</security>
</binding>
可执行文件的app.config
<client>
<endpoint address="https://U-WM-3vIntegr8/test/Web/Services/Diagnostic.svc"
binding="basicHttpBinding" bindingConfiguration="ClientHttpEndpoint"
contract="Test.IDiagnostic" name="ClientDiagnosticEndpoint" />
</client>
<basicHttpBinding>
<binding name="ClientHttpEndpoint" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="1048576"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
......来自客户
public static IDiagnostic GetDiagnosticService()
{
return new ChannelFactory<IDiagnostic>("ClientDiagnosticEndpoint").CreateChannel();
}
答案 0 :(得分:2)
您需要手动填写凭据,它们不会自动在此配置中传递。如果这就是你要找的东西,你应该在客户端和服务器上将clientCredentialType设置为“Windows”。现在你需要手动设置它:
proxy.ClientCredentials.Username.User = ""
proxy.ClientCredentials.Username.Password = ""