locked
Host WCF dataservice via WebScriptServiceHostFactory RRS feed

  • Question

  • Hi,

    I have a WCF Dataservice that uses System.Data.Services.DataServiceFactory, following is code in my svc file

    //NwService.svc

    <%

     

    @ ServiceHost Language="C#"

    Factory

     

     

    ="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

    Service

     

     

    ="NWSite.NWService" %>

     

    This work great.

    Now I want to use this service from Javascript, with my limited knowledge about WCF Dataservices I understand that to use the WCF Dataservice in Javascript I need to use the WebScriptServiceHostFactory.

    I added another .svc file to my project and added following code to it

    //TestSvc.svc

    <%

     

    @ ServiceHost Language="C#"

     

     

    Service="NWSite.NWService"

     

     

    Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"%>

    When I navigate to TestSvc.svc file in browser I get following exception, what am I doing wrong, How can I fix it?

    Thanks,

    Navneet

     

    Server Error in '/' Application.

    Operation 'ProcessRequestForMessage' in contract 'IRequestHandler' specifies Method '*' on the WebGetAttribute/WebInvokeAttribute, but the only allowed values for Method are GET or POST. Other values are not supported by 'System.ServiceModel.Description.WebScriptEnablingBehavior'.

     

     

     


    Navneet
    Tuesday, August 17, 2010 6:33 PM

Answers

  • Hi,

    Data service needs the DataServiceHostFactory to work. Note that each data service already supports both ATOM/XML as well as JSON formats. The format is determined by the Content-Type and Accept headers in the requests/responses (standard HTTP content type negotiation). So if you're using the data service from a javascript you can send normal HTTP requests to the service and it's up to you if you wan the data in the request/response to be ATOM/XML or JSON. Just set the Content-Type and Accept headers accordingly.

    Thanks,


    Vitek Karas [MSFT]
    Wednesday, August 18, 2010 9:20 AM
    Moderator
  • Navneet,

    The ablity of a data service to send response in ATOM/JSON is not dependent on the host. Data services can only be hosted in  DataServiceHost. if you have data service hosted either via WebServiceHost or IIS, making a request to the service with the "accept" header set to "application/json" will result in the server sending the response in JSON. This JSON can be consumed by your Javascript client library and produce objects to use.


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Thursday, August 19, 2010 8:13 AM
    Moderator

All replies

  • Hi,

    Data service needs the DataServiceHostFactory to work. Note that each data service already supports both ATOM/XML as well as JSON formats. The format is determined by the Content-Type and Accept headers in the requests/responses (standard HTTP content type negotiation). So if you're using the data service from a javascript you can send normal HTTP requests to the service and it's up to you if you wan the data in the request/response to be ATOM/XML or JSON. Just set the Content-Type and Accept headers accordingly.

    Thanks,


    Vitek Karas [MSFT]
    Wednesday, August 18, 2010 9:20 AM
    Moderator
  • Hi Vitek,

    Thanks for your response. Where can I find for sample JavaScript that uses DataServiceHostFactory?

    Regards,

    Navneet


    Navneet
    Wednesday, August 18, 2010 4:23 PM
  • Navneet,

    The ablity of a data service to send response in ATOM/JSON is not dependent on the host. Data services can only be hosted in  DataServiceHost. if you have data service hosted either via WebServiceHost or IIS, making a request to the service with the "accept" header set to "application/json" will result in the server sending the response in JSON. This JSON can be consumed by your Javascript client library and produce objects to use.


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Thursday, August 19, 2010 8:13 AM
    Moderator