【问题标题】:Server architecture and SubSonic服务器架构和 SubSonic
【发布时间】:2009-04-19 11:08:59
【问题描述】:

我正在尝试开发服务器/客户端应用程序。服务器将是一堆 Web 服务,其想法是公开如下方法:

公司 GetNewCompany(); //创建一个新的公司对象
保存(C 公司);
CompanyCollection GetCompany(查询 q);

Query 对象是 Subsonic 2.1 的一部分。但问题是 SubSonic 不是为此而构建的,我在这里错过了什么吗?还是无法通过 SOAP 使用亚音速查询语言?

这本来是很棒的功能,因为使用亚音速制作应用服务器真的很容易。

溴 索伦。

【问题讨论】:

    标签: web-services subsonic


    【解决方案1】:

    如果你想使用 subsonic v3,你可以看看这个关于 IUpdatable 的问题: http://code.google.com/p/subsonicthree/issues/detail?id=30

    这将让您使用 ado 数据服务有些痛苦。您使用带有 URI 参数的 DB 构造函数。这可能不会成为 v3 的一部分,但您可以自己进行这样的更改。

    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);
            }
        }
    }
    

    这就是服务的全部内容:

    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;
            }
        }
    }
    

    对于 web.config:

      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
      </system.serviceModel>
    

    【讨论】:

    猜你喜欢
    • 2011-04-17
    • 1970-01-01
    • 2020-05-29
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多