How to Call .NET AuthenticationService from json client without ASP.NET

久未见 提交于 2019-12-06 02:06:02

Yes the AuthenticationService can handle JSON. There are a couple of ways to do. Here is a sample configuration I've used in the past using the element.

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

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!