locked
Suggestions for RESTful service that requires object parameters RRS feed

  • Question

  • I have written a WCF service that uses the SOAP protocol with WsHttpBinding and security set to TransportWithMessageCredential.  The user is authenticated using the Membership Provider.  This is working just fine.  However, the more that I read about Windows 8, as well as using other devices, I think this service will eventually need to be converted to REST.  I downloaded some of the examples and have a few questions.  If anyone has any good references or suggestions, I would really appreciate it. 

      • How do you authenticate a client using REST?  I saw something about an Authorization header, but do not know how to use it. 
      • How do you handle object parameters?  Most of my methods involve uploading some kind of file, so I have an object that consists of a byte array along with several other properties.  I have seen some suggestions about using a UriTemplate and putting the properties as part of the Uri and the byte array as a Stream.  However, that seems pretty insecure and could entail huge Uri's if new parameters are added. 
      • Regarding question 2, some of the examples use objects for WebInvoke input parameters, but are these interoperable?
      • Would using oData solve the problem for question 2?  Are there any good examples of this with a RESTful service?
      • Do I have to do something special if the client wants JSON vs. XML?

    I did download the WCF REST Service template, but I am not sure how to set up the client part based on the information included. 

    Thanks for all your help!


    Christine A. Piffat

    Tuesday, September 11, 2012 6:22 PM

Answers

  • >How do you authenticate a client using REST?  I saw something about an Authorization header, but do not know how to use it. 

    Hi, As far as I know , the best for REST service is to use OAuth. Please refer to the link below:

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f938eb28-7ec9-47f9-8c51-89b0952f7642

    Authorization header is just a header that contains tokens

    >How do you handle object parameters?  Most of my methods involve uploading some kind of file, so I have an object that consists of a byte array along with several other properties.  I have seen some suggestions about using a UriTemplate and putting the properties as part of the Uri and the byte array as a Stream.  However, that seems pretty insecure and could entail huge Uri's if new parameters are added. 
    >Would using oData solve the problem for question 2?  Are there any good examples of this with a RESTful service?

    Please refer to the link below:

    WCF Web HTTP Programming Model Overview

    >Regarding question 2, some of the examples use objects for WebInvoke input parameters, but are these interoperable?

    It is in Request\Reply model, not in duplex model.

    >Do I have to do something special if the client wants JSON vs. XML?

    Please refer to the thread below:

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/2f31d2d7-470d-4b19-8288-3402c05bdc63/

        [ServiceContract]
        public interface IService1
        {
            //http://localhost:7662/Service1.svc/GetAppointmentJson?companyId=1&appointmentDate=1
            [OperationContract]
            [WebGet(UriTemplate = "GetAppointmentJson?companyId={companyId}&appointmentDate={appointmentDate}",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare)]
            GetAppointmentList GetAppointmentJson(int companyId, int appointmentDate);
            //http://localhost:7662/Service1.svc/getAppointmentXML?companyId=1&appointmentDate=1
            [OperationContract]
            [WebGet(UriTemplate = "GetAppointmentXML?companyId={companyId}&appointmentDate={appointmentDate}",
                RequestFormat = WebMessageFormat.Xml,
                ResponseFormat = WebMessageFormat.Xml,
                BodyStyle = WebMessageBodyStyle.Bare)]
            GetAppointmentList GetAppointmentXML(int companyId, int appointmentDate);
        }
    

    Hope helpful.

    • Marked as answer by Christy Piffat Friday, September 14, 2012 8:39 PM
    Friday, September 14, 2012 3:09 AM