如何在没有ASP.NET的情况下从JSON客户端调用.NET AuthenticationService [英] How to Call .NET AuthenticationService from json client without ASP.NET

查看:122
本文介绍了如何在没有ASP.NET的情况下从JSON客户端调用.NET AuthenticationService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a WCF 4 service which is in a Secure subfolder, accessible after the client has authenticated using Forms authentication using the .NET AuthenticationService.

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

This WCF service is for a mobile app client which communicates via json but is not an ASP.NET app. I have successfully configured the service to use json and the AuthenticationService has the standard configuration as documented in many places e.g. http://msdn.microsoft.com/en-us/library/bb398990.aspx

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

The docmentation for the AuthenticationService says "The application must be able to send and consume a SOAP message". However I want the client to be able to use json for authentication as well. Is this possible? What's the configuration required?

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

I found this article http://weblogs.asp.net/asptest/archive/2008/12/09/working-with-the-asp-net-ajax-authentication-service.aspx so it looks like the AuthenticationService can handle json but it uses Client Application Services. The mobile app client is not an ASP.NET app.

推荐答案

这个问题已经存在很长时间了,但是我认为如果我发布答案会有所帮助.

The question is old for long time but I think it will help someone if I post my answer.

确保可以为AuthenticationService返回json. 该解决方案非常简单,就像Garret回答一样,您只需要配置另一个端点即可,但是您需要为端点行为添加2个附加属性:defaultOutgoingResponseFormat ="Json"和defaultBodyStyle ="Wrapped"以覆盖默认的肥皂响应.

For sure you can return json for AuthenticationService. The solution is very simple like Garret answer, you only need configure another endpoint like this but you need add 2 addition attributes for endpoint behaviors: defaultOutgoingResponseFormat="Json" and defaultBodyStyle="Wrapped" to overwrite default soap response.

<system.serviceModel>
<services>
  <service behaviorConfiguration="AuthenticationServiceBehaviors" name="System.Web.ApplicationServices.AuthenticationService">
    <endpoint address="" behaviorConfiguration="ajaxBehavior"
               contract="System.Web.ApplicationServices.AuthenticationService"
               binding="webHttpBinding" bindingConfiguration="RestBinding"
               bindingNamespace="http://asp.net/ApplicationServices/v200"/>
  </service>
</services>
<bindings>
      <webHttpBinding>
    <binding name="RestBinding" />
  </webHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="ajaxBehavior">
      <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="AuthenticationServiceBehaviors">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

我希望这对希望将asp.net成员身份公开为json格式以便在移动应用中使用的人有所帮助.

I hope this help someone who want to expose asp.net membership as json format to use in mobile app.

这篇关于如何在没有ASP.NET的情况下从JSON客户端调用.NET AuthenticationService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆