RIA Services - exposing JSON endpoint


Go through RIA Services - using Entity Framework article which demonstrates step by step approach to expose and consume Domain service in Silverlight application.

This article speaks about exposing JSON endpoint which can be consumed by AJAX client.

By default only Binary endpoint is enabled for domain services. To use the Binary endpoint no additional configuration is needed. But to enable JSON endpoint you have to do small change. Enabling JSON endpoint does not need any change in domain service, you have to just register endpoint factory in the Web.config file.

<domainServices>
      <endpoints>
        <add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </endpoints>
</domainServices>

And you must add reference of "Microsoft.ServiceModel.DomainServices.Hosting" assembly in web project. The Microsoft.ServiceModel.DomainServices.Hosting.dll assembly is part of WCF RIA Services toolkit, to use this you must first install WCF RIA Services toolkit.

1.gif

Now build your application, to see the JSON output hit below URL.

http://localhost:52878/RIASample-Web-StudentDomainService.svc/Json/GetStudent_detail

Note that the URL is combination of namespace and domain service name. The "GetStudent_detail" is method in domain service.

2.gif

When you hit the URL it will prompt you to save the output, you may save it in your system and open it in notepad. The above image is showing output in notepad.


Similar Articles