views:

119

answers:

1

Hello! Im trying to develop an server /client application. The server will be a bunch of webservices, the idea was to expose methods like:

Company GetNewCompany(); //Creates an new Company Object
Save(Company C);
CompanyCollection GetCompany(Query q);

Where Query object is part of Subsonic 2.1. But the problem is that SubSonic is not built for this, Have I missed something here? or is it just impossible to to use subsonic query language over SOAP?

This would have been great feature, becuase then it is really easy to make an application server using subsonic.

Br Soren.

+2  A: 

If you want to use subsonic v3 you can look at this issue that talks about IUpdatable: http://code.google.com/p/subsonicthree/issues/detail?id=30

This will let you use ado data services somewhat painlessly. You use a DB constructor that take a URI argument. This probably won't be a part of v3 but you could make changes like this yourself.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WcfClientTest.NorthwindService;

namespace WcfClientTest
{
    /// <summary>
    /// Summary description for WcfTest
    /// To run these tests, load this project, and somehow get a server running at the URI. 
    /// This can be done by updating the service reference to start the development server.
    /// </summary>
    [TestClass]
    public class WcfTest
    {
        private string baseURI = "http://127.0.0.1:49649/Northwind.svc";
        private DB ctx;

        /// <summary>
        /// Sets up test.
        /// </summary>
        [TestInitialize]
        public void SetUp()
        {
            ctx = new DB(new Uri(baseURI));
        }

        [TestCleanup]
        public void Cleanup()
        {
        }

        [TestMethod]
        public void Select_Simple_With_Variable()
        {
            int categoryID = 5;
            IQueryable<Product> result = from p in ctx.Products
                                         where p.CategoryID == categoryID
                                         select p;

            List<Product> products = result.ToList();
            Assert.AreEqual(7, products.Count());
        }

        [TestMethod]
        public void TestAddNew()
        {
            // add customer
            var c = new Customer
                        {
                            CustomerID = "XXXXX",
                            ContactTitle = "Prez",
                            Country = "USA",
                            ContactName = "Big Guy",
                            CompanyName = "Big Guy Company"
                        };
            ctx.AddToCustomers(c);
            ctx.SaveChanges();

            IQueryable<Customer> qCustomer = from cust in ctx.Customers
                                             where cust.CustomerID == "XXXXX"
                                             select cust;

            Customer c2 = qCustomer.FirstOrDefault();

            Assert.AreEqual("XXXXX", c2.CustomerID);

            if (c2 != null)
            {
                ctx.DeleteObject(c2);
            }
            ctx.SaveChanges();

            IQueryable<Customer> qCustomer2 = from cust in ctx.Customers
                                              where cust.ContactName == "Big Guy"
                                              select cust;
            // Returns null if the row isn't found.
            Customer c3 = qCustomer2.SingleOrDefault();
            Assert.AreEqual(null, c3);
        }
    }
}

And this is all there is to the service:

using System.Data.Services;
using Northwind;

namespace NorthwindService
{
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=false)]
    public class Northwind: DataService<DB>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.UseVerboseErrors = true;
        }
    }
}

And for web.config:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  </system.serviceModel>
P a u l
See: http://blogs.msdn.com/aconrad/archive/2008/12/05/developing-an-astoria-data-provider-for-subsonic.aspxThat's where I got it from.
P a u l