我正在尝试使用WCF使用启用了WS-Security的服务。身份验证使用UsernameToken。我对WCF Web服务客户端不是很了解,但我认为我的配置适用于常规HTTP通信。我(大部分)使用this guide来配置它。主要区别在于我使用VS2010“添加服务引用”UI而不是命令提示符。
我的问题是我需要通过HTTPS执行此操作。当我在app.config中使用<security mode="Message">
时,我相信我的soap信封包含所需的WS-Security标头。我无法确定,因为我无法登录工作。但是,我收到以下错误:The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
。
以下是我的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>
var service = new OmittedClient();
service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";
var response = service.DoSomething(new DoSomethingRequest());
答案 0 :(得分:1)
感谢500 - 内部服务器错误帮助我解决问题。以下是我采取的步骤:
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);