如何通过HTTPS使用WCF中的WS-Security服务?
我正在尝试使用支持WS-Security的WCF服务。身份验证使用UsernameToken工作。我对WCF web服务客户端不是很熟悉,但我认为下面的配置适用于常规HTTP通信。我(主要)用来配置它。主要区别在于我使用了VS2010“添加服务引用”UI而不是命令提示符 我的问题是,我需要通过HTTPS来实现这一点。当我在app.config中使用如何通过HTTPS使用WCF中的WS-Security服务?,wcf,soap,ws-security,Wcf,Soap,Ws Security,我正在尝试使用支持WS-Security的WCF服务。身份验证使用UsernameToken工作。我对WCF web服务客户端不是很熟悉,但我认为下面的配置适用于常规HTTP通信。我(主要)用来配置它。主要区别在于我使用了VS2010“添加服务引用”UI而不是命令提示符 我的问题是,我需要通过HTTPS来实现这一点。当我在app.config中使用时,我相信我的soap信封包含所需的WS-Security头。我不能确定,因为我不能让日志工作。但是,我得到以下错误:提供的URI方案“https”无
时,我相信我的soap信封包含所需的WS-Security头。我不能确定,因为我不能让日志工作。但是,我得到以下错误:提供的URI方案“https”无效;应为“http”。参数名称:通过
下面是我的app.config文件的内容,以及我的客户端代码示例
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Omitted" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Message">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" negotiateServiceCredential="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://omitted.com/service" binding="wsHttpBinding" bindingConfiguration="Omitted" contract="Omitted.Omitted" name="Omitted" />
</client>
</system.serviceModel>
感谢500-内部服务器错误帮助我解决了这个问题。以下是我采取的步骤:
HTTPS是一种传输安全模式。是的,但如何使用消息安全性?使用UsernameToken是否需要消息安全性?请使用TransportWithMessageCredential模式。请原谅,我的帖子似乎有问题。
var service = new OmittedClient();
service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";
var response = service.DoSomething(new DoSomethingRequest());
var client = new WebServiceClient();
client.ClientCredentials.UserName.UserName = "USERNAME";
client.ClientCredentials.UserName.Password = "PASSWORD";
// WCF complains about a missing timestamp (http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages)
var elements = service.Endpoint.Binding.CreateBindingElements();
elements.Find().IncludeTimestamp = false;
service.Endpoint.Binding = new CustomBinding(elements);