【发布时间】:2019-09-13 00:18:02
【问题描述】:
我正在尝试使用 UserName 配置 WCF 身份验证,但没有成功,我已经尝试了很多我已经找到的解决方案,但似乎没有什么对我有用。
HTTP 请求未经客户端身份验证方案授权 '匿名的'。从服务器收到的身份验证标头是 'Negotiate,NTLM,Basic realm="localhost"'.
服务器设置
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" negotiateServiceCredential="false" />
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Namespace.Service" behaviorConfiguration="wsHttpBehavior">
<endpoint binding="wsHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" name="Soap" bindingNamespace="/WebServices" contract="Namespace.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" name="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wsHttpBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="UserNamePasswordValidator, WebApplication" />
<!--<serviceCertificate findValue="ServiceModelSamples-HTTPS-Server" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />-->
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
在客户端
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Soap">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:85/WebServices/Service.svc"
binding="wsHttpBinding" bindingConfiguration="Soap" contract="ServiceReference1.IService"
name="Soap" />
</client>
</system.serviceModel>
我发现的大多数解决方案都使用 Windows 传输,我只需要通过用户名进行身份验证。
我检查一下:
- https://blog.sandervanlooveren.be/posts/securing-a-wcf-service-with-username-and-password/
- https://docs.microsoft.com/en-us/dotnet/framework/wcf/samples/ws-transport-with-message-credential
我尝试了安全 mode="Message" 和安全 mode="TransportWithMessageCredential" 均未成功
我的客户端代码如下:
// Instantiate the proxy
var proxy = new ServiceClient();
proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "password";
请任何人检查我的配置并告诉我设置错误吗?
编辑: 这是 ASP.Net MVC5 应用程序中的一个服务,这也是一个问题吗?
【问题讨论】:
标签: c# .net wcf authentication iis