繁体   English   中英

WCF-TransportWithMessageCredential使用客户端身份验证方案“匿名”对HTTP请求进行未授权

[英]WCF-TransportWithMessageCredential The HTTP request is unauthorized with client authentication scheme 'Anonymous'

我正在尝试使用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>

这是我的IIS配置 在此处输入图片说明

我发现的大多数解决方案都使用Windows传输,我只需要通过用户名进行身份验证。

我检查一下:

我尝试了安全模式=“ Message”和安全模式=“ TransportWithMessageCredential”,但未成功

我的客户代码如下:

 // Instantiate the proxy  
 var  proxy = new ServiceClient();

 proxy.ClientCredentials.UserName.UserName = "username";
 proxy.ClientCredentials.UserName.Password = "password";

任何人都可以检查我的配置并告诉我我设置错了吗?

编辑:这是ASP.Net MVC5应用程序内的服务,这也可能是问题吗?

customUserNamePasswordValidatorType属性字符串可能存在问题,通常采用以下形式

customUserNamePasswordValidatorType="Namespace.MyCustUserNamePasswordVal,Namespace"

您可以访问托管服务的WSDL吗? 另外,打开匿名身份验证就足够了,不需要启用其他身份验证。
这是我的配置,我使用了WCF4.5中支持的简化配置,希望它对您有用。

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>
            <userNameAuthentication customUserNamePasswordValidatorType="WcfService1.CustUserNamePasswordVal,WcfService1" userNamePasswordValidationMode="Custom"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding>
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

请随时告诉我是否有什么可以帮助的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM