简体   繁体   English

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

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

I'm trying to configure WCF authentication with UserName but without success, I have tried aa lot of solution that I found already, but nothing seem to work for me. 我正在尝试使用UserName配置WCF身份验证,但是没有成功,我已经尝试了很多已经找到的解决方案,但似乎没有任何用处。

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 客户端身份验证方案“匿名”未授权HTTP请求。 The authentication header received from the server was 'Negotiate,NTLM,Basic realm="localhost"'. 从服务器收到的身份验证标头是“ Negotiate,NTLM,Basic realm =“ localhost””。

Server setting 服务器设定

<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>

On the client side 在客户端

<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>

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

Most of solution that I found use Windows Transport, I need Authentication only through Username. 我发现的大多数解决方案都使用Windows传输,我只需要通过用户名进行身份验证。

I check this : 我检查一下:

I have tried security mode="Message" and security mode="TransportWithMessageCredential" without success 我尝试了安全模式=“ Message”和安全模式=“ TransportWithMessageCredential”,但未成功

My client code look like : 我的客户代码如下:

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

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

Please can anyone check my config and tell what I'm setting wrong ? 任何人都可以检查我的配置并告诉我我设置错了吗?

Edit: This is a Service inside an ASP.Net MVC5 App, Can this also be a problem ? 编辑:这是ASP.Net MVC5应用程序内的服务,这也可能是问题吗?

There might be something amiss with the customUserNamePasswordValidatorType property string.It is usually in the following form customUserNamePasswordValidatorType属性字符串可能存在问题,通常采用以下形式

customUserNamePasswordValidatorType="Namespace.MyCustUserNamePasswordVal,Namespace"

Can you access the WSDL of hosting service? 您可以访问托管服务的WSDL吗? Also, turning on the anonymous authentication is enough, unnecessary to enable others authentication. 另外,打开匿名身份验证就足够了,不需要启用其他身份验证。
Here is my configuration, I used simplified configuration which be supported in WCF4.5, wish it is useful to you. 这是我的配置,我使用了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>

Feel free to let me know If there is anything I can help with. 请随时告诉我是否有什么可以帮助的。

暂无
暂无

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

相关问题 使用客户端身份验证方案“匿名”对HTTP请求进行未经授权的授权? - The HTTP request is unauthorized with client authentication scheme 'Anonymous'? 客户端身份验证方案“匿名”未授权HTTP请求。 消耗wsdl文件 - The HTTP request is unauthorized with client authentication scheme 'Anonymous'. consuming wsdl file 异常= HTTP请求未经客户端身份验证方案“匿名”授权 - Exception = The HTTP request is unauthorized with client authentication scheme 'Anonymous' Wcf服务异常“使用客户端身份验证方案未授权HTTP请求” - Wcf service exception “The HTTP request is unauthorized with client authentication scheme” 客户端身份验证方案“匿名”未授权HTTP请求。 从服务器收到的身份验证标头 - The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server HTTP 请求未经客户端身份验证方案“Ntlm”授权 - The HTTP request is unauthorized with client authentication scheme 'Ntlm' 客户端身份验证方案“匿名”未授权HTTP请求。 从服务器收到的身份验证标头为“基本” - The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic HTTP 请求未经授权,客户端身份验证方案为“匿名”。 从服务器收到的身份验证标头是“基本领域” - The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic Realm’ HTTP请求使用客户端身份验证方案“匿名”(通过C#基本身份验证写入)未经授权 - The HTTP request is unauthorized with client authentication scheme 'Anonymous' (Write via C# basic authentication) 客户端身份验证方案“匿名”禁止HTTP请求。 3 - The HTTP request was forbidden with client authentication scheme 'Anonymous'. 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM