locked
WCF Service with EF 6+ and WCF DS 5.6.2 how to provide SOAP and REST RRS feed

  • Question

  • Dear community.

    I Have a WCF Service utilizing EF 6.1.1 and WCF Data Services 5.6.2. Created by following this oData team blog post

    Now I would like to configure it to return SOAP as well as oData/Rest.
    How can I accomplish this? I have found several threads about this and tried many solutions but I couldn't get them to work and most of them seem to be outdated 

    Monday, November 24, 2014 10:33 PM

Answers

  • Hello vipasane,

    >> Now I would like to configure it to return SOAP as well as oData/Rest.

    From your description, it seems that you want to configure the service project both SOAP and Rest. If it is, you could check this demo example which uses EF 6.X and WCF Data Service 5.6.2:

    The tested table:

    CREATE TABLE [dbo].[Order] (
    
        [OrderID]   INT           NOT NULL,
    
        [OrderName] NVARCHAR (50) NOT NULL,
    
        PRIMARY KEY CLUSTERED ([OrderID] ASC)
    
    );
    

    After creating the EF model, configuring the interface to get the list of Order entities and its implementation:

    [ServiceContract]
    
        public interface IService1
    
        {
    
            IList<Order> GetOrders();
    
        }
    
    public class Service1 : IService1
    
        {
    
            WCFDBEntities db = new WCFDBEntities();
    
            public IList<Order> GetOrders()
    
            {
    
                return db.Orders.ToList();
    
            }
    
        }
    

    If you use the WCF Test Client to check the GetOrders method, you could see the transfer data is SOAP message.

    Then create the WCF Data Service item and according to that blog, after configuring it, it should be:

    public class WcfDataService1 : EntityFrameworkDataService<WCFDBEntities>
    
        {
    
            // This method is called only once to initialize service-wide policies.
    
            public static void InitializeService(DataServiceConfiguration config)
    
            {
    
                // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
    
                // Examples:
    
                config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    
            }
    
        }
    

    Then you could odata protocol to get the orders lists. Or you could create a console application as the client as below:

    namespace Client
    
    {
    
        class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                #region SOAP
    
                SOAPReference.Service1Client client = new SOAPReference.Service1Client();
    
                var soapOrders = client.GetOrders().ToList();
    
                #endregion
    
    
                #region Rest
    
                RestReference.WCFDBEntities db = new RestReference.WCFDBEntities(new Uri("http://localhost:57232/WcfDataService1.svc"));
    
                var restOrders = db.Orders.ToList();
    
                #endregion
    
            }
    
        }
    
    }
    

    If this does not work for you, please let me know.

    Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 25, 2014 7:26 AM
    Moderator

All replies

  • You should post to the WCF Data Service.

    Tuesday, November 25, 2014 4:55 AM
  • Hello vipasane,

    >> Now I would like to configure it to return SOAP as well as oData/Rest.

    From your description, it seems that you want to configure the service project both SOAP and Rest. If it is, you could check this demo example which uses EF 6.X and WCF Data Service 5.6.2:

    The tested table:

    CREATE TABLE [dbo].[Order] (
    
        [OrderID]   INT           NOT NULL,
    
        [OrderName] NVARCHAR (50) NOT NULL,
    
        PRIMARY KEY CLUSTERED ([OrderID] ASC)
    
    );
    

    After creating the EF model, configuring the interface to get the list of Order entities and its implementation:

    [ServiceContract]
    
        public interface IService1
    
        {
    
            IList<Order> GetOrders();
    
        }
    
    public class Service1 : IService1
    
        {
    
            WCFDBEntities db = new WCFDBEntities();
    
            public IList<Order> GetOrders()
    
            {
    
                return db.Orders.ToList();
    
            }
    
        }
    

    If you use the WCF Test Client to check the GetOrders method, you could see the transfer data is SOAP message.

    Then create the WCF Data Service item and according to that blog, after configuring it, it should be:

    public class WcfDataService1 : EntityFrameworkDataService<WCFDBEntities>
    
        {
    
            // This method is called only once to initialize service-wide policies.
    
            public static void InitializeService(DataServiceConfiguration config)
    
            {
    
                // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
    
                // Examples:
    
                config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
    
            }
    
        }
    

    Then you could odata protocol to get the orders lists. Or you could create a console application as the client as below:

    namespace Client
    
    {
    
        class Program
    
        {
    
            static void Main(string[] args)
    
            {
    
                #region SOAP
    
                SOAPReference.Service1Client client = new SOAPReference.Service1Client();
    
                var soapOrders = client.GetOrders().ToList();
    
                #endregion
    
    
                #region Rest
    
                RestReference.WCFDBEntities db = new RestReference.WCFDBEntities(new Uri("http://localhost:57232/WcfDataService1.svc"));
    
                var restOrders = db.Orders.ToList();
    
                #endregion
    
            }
    
        }
    
    }
    

    If this does not work for you, please let me know.

    Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 25, 2014 7:26 AM
    Moderator