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

编程入门 行业动态 更新时间:2024-10-09 13:31:34
本文介绍了如何在没有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具有许多地方记录的标准配置,例如 msdn.microsoft/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. msdn.microsoft/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?

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

I found this article weblogs.asp/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="asp/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成员身份公开为json格式以便在移动应用中使用的人有所帮助.

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

更多推荐

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

本文发布于:2023-11-07 15:43:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   情况下   如何在   ASP   AuthenticationService

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!