我有一个使用基本的HTTP身份验证模式的WebHTTPBinding服务,但是对于某些奇怪的原因,它验证了对Windows帐户提供的用户名/密码,以为我指定了UsernamePasswordValidationMode=“MembershipProvider”。

我发现了报告这个问题的其他帖子,但没有给出这种情况的答案。

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="WebBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EPWeb">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="SqlProvider" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Foo">
        <endpoint address="Test" behaviorConfiguration="EPWeb"
            binding="webHttpBinding" bindingConfiguration="WebBinding"
            contract="Foo.IService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:3456/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
.

有帮助吗?

解决方案

This configuration will not work. But there are workarounds to this issue:

  • Create Login() method and use authentication token, which you pass to every service method.
  • Use custom validation mode, and validate username\password by code, using Membership.ValidateUser()

其他提示

Token passed login or a custom http authentication module.

Here is a link to a custom authentication module. http://custombasicauth.codeplex.com/

For token based, you could use an OAuth implementation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top