wcf - 如何在没有 ASP.NET 的情况下从 json 客户端调用 .NET AuthenticationService

标签 wcf json forms-authentication

我有一个 WCF 4 服务,它位于 Secure 子文件夹中,在客户端使用 .NET AuthenticationService 使用 Forms 身份验证进行身份验证后可以访问。

此 WCF 服务适用于通过 json 进行通信但不是 ASP.NET 应用程序的移动应用程序客户端。我已经成功地将服务配置为使用 json,并且 AuthenticationService 具有许多地方记录的标准配置,例如http://msdn.microsoft.com/en-us/library/bb398990.aspx

AuthenticationService 的文档说“应用程序必须能够发送和使用 SOAP 消息”。但是我希望客户端也能够使用 json 进行身份验证。这可能吗?需要什么配置?

我找到了这篇文章 http://weblogs.asp.net/asptest/archive/2008/12/09/working-with-the-asp-net-ajax-authentication-service.aspx所以看起来 AuthenticationService 可以处理 json 但它使用客户端应用程序服务。移动应用程序客户端不是 ASP.NET 应用程序。

最佳答案

是的,AuthenticationService 可以处理 JSON。有几种方法可以做到。这是我过去使用 使用的示例配置元素。

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

    <services>
      <service name="System.Web.ApplicationServices.AuthenticationService" behaviorConfiguration="MyServiceBehavior">
        <endpoint address="" behaviorConfiguration="ajaxBehavior"
                  contract="System.Web.ApplicationServices.AuthenticationService"
                  binding="webHttpBinding" bindingConfiguration="webHttpBindingSecure"
                  bindingNamespace="http://asp.net/ApplicationServices/v200"/>
      </service>
    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="ajaxBehavior">
          <enableWebScript/>
        </behavior>

      </endpointBehaviors>
      <serviceBehaviors>

        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingSecure">
          <security mode="Transport"/>
        </binding>
      </webHttpBinding>
    </bindings>
</system.serviceModel>

关于wcf - 如何在没有 ASP.NET 的情况下从 json 客户端调用 .NET AuthenticationService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8918322/

相关文章:

asp.net - WCF 中的 405 方法不允许错误

c# - Fiddler 根据请求向 WCF 服务 PUT/POST 提供 411 错误

vb.net - 暴露 WCF 服务无法通过 windows 防火墙检索对象

PHP解码json并显示

java - Hibernate 延迟加载抛出 JsonMappingException

asp.net - HttpContext.User.Identity 为空

ASP.NET MVC 应用程序设置 loginUrl 接受

WCF:由于身份验证失败,无法满足安全 token 的请求

json - 领域与属性(property)

asp.net - 可以让 iisnode 下的 NodeJS 应用程序使用 ASP.NET FormsAuthentication 进行身份验证吗?