[MOSS2010]利用BCS进行数据集成(二)

书接上回,继续解决苦苦困扰我的那个SoapServerException

今天摘要性的看了这篇博文,博主的实现跟我相比有两点不同

没有删掉Customer类

使用了twitter API

相对来讲,第一点显然是更大的区别,尝试着按照博主的方法去做,果然成功了!

[MOSS2010]利用BCS进行数据集成(二)_第1张图片

 

目前的代码和bdcm文件如下

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using BdcModel.DBModel;

namespace BdcModel
{
    public class ProductService
    {
        private const string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True";
        private static readonly NorthWindDataContext dataContext = new NorthWindDataContext(connectionString);

        public static Product ReadItem(int id)
        {
            return (from p in dataContext.Products
                    where p.ProductID == id
                    select new Product
                    {
                        ProductID = p.ProductID,
                        ProductName = p.ProductName
                    }).FirstOrDefault();
        }

        public static IEnumerable<Product> ReadList()
        {
            return from p in dataContext.Products
                   select new Product
                   {
                       ProductID = p.ProductID,
                       ProductName = p.ProductName
                   };
        }

        public static void Update(Product product)
        {
            var productToUpdate = dataContext.Products.SingleOrDefault(p => p.ProductID == product.ProductID);
            productToUpdate.ProductName = product.ProductName;
            dataContext.SubmitChanges();
        }
    }
}

 

<?xml version="1.0" encoding="utf-8"?>
<Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog" Name="BdcModel">
  <LobSystems>
    <LobSystem Name="BdcModel" Type="DotNetAssembly">
      <LobSystemInstances>
        <LobSystemInstance Name="BdcModel" />
      </LobSystemInstances>
      <Entities>
        <Entity Name="Product" Namespace="BdcModel" EstimatedInstanceCount="1000" Version="1.0.0.8">
          <Properties>
            <Property Name="Class" Type="System.String">BdcModel.ProductService, BdcModel</Property>
          </Properties>
          <Identifiers>
            <Identifier Name="ProductID" TypeName="System.Int32" />
          </Identifiers>
          <Methods>
            <!-- start finder method -->
            <Method Name="ReadList">
              <Parameters>
                <Parameter Direction="Return" Name="returnParameter">
                  <TypeDescriptor TypeName="System.Collections.Generic.IEnumerable`1[[BdcModel.Product, BdcModel]]" IsCollection="true" Name="ProductList">
                    <TypeDescriptors>
                      <TypeDescriptor TypeName="BdcModel.Product, BdcModel" Name="Product">
                        <TypeDescriptors>
                          <TypeDescriptor TypeName="System.Int32" IdentifierName="ProductID" Name="ProductID" />
                          <TypeDescriptor TypeName="System.String" Name="ProductName" />
                        </TypeDescriptors>
                      </TypeDescriptor>
                    </TypeDescriptors>
                  </TypeDescriptor>
                </Parameter>
              </Parameters>
              <MethodInstances>
                <MethodInstance Type="Finder" ReturnParameterName="returnParameter" Default="true" Name="ReadList" DefaultDisplayName="Product List" />
              </MethodInstances>
            </Method>
            <!-- end finder method -->
            <!-- start specific finder method -->
            <Method Name="ReadItem">
              <Parameters>
                <Parameter Direction="In" Name="id">
                  <TypeDescriptor TypeName="System.Int32" IdentifierName="ProductID" Name="ProductID" />
                </Parameter>
                <Parameter Direction="Return" Name="returnParameter">
                  <TypeDescriptor TypeName="BdcModel.Product, BdcModel" Name="Product">
                    <TypeDescriptors>
                      <TypeDescriptor TypeName="System.Int32" IdentifierName="ProductID" Name="ProductID" />
                      <TypeDescriptor TypeName="System.String" Name="ProductName" />
                    </TypeDescriptors>
                  </TypeDescriptor>
                </Parameter>
              </Parameters>
              <MethodInstances>
                <MethodInstance Type="SpecificFinder" ReturnParameterName="returnParameter" Default="true" Name="ReadItem" DefaultDisplayName="Read Product" />
              </MethodInstances>
            </Method>
            <Method Name="Update">
              <Parameters>
                <Parameter Name="product" Direction="In">
                  <TypeDescriptor Name="Product" TypeName="BdcModel.Product, BdcModel">
                    <TypeDescriptors>
                      <TypeDescriptor Name="ProductID" IdentifierName="ProductID" TypeName="System.Int32" UpdaterField="true" />
                      <TypeDescriptor Name="ProductName" TypeName="System.String" UpdaterField="true" /></TypeDescriptors></TypeDescriptor></Parameter>
              </Parameters>
              <MethodInstances>
                <MethodInstance Name="Update" Type="Updater" />
              </MethodInstances></Method>
            <!-- end specific finder method -->
          </Methods>
        </Entity>
      </Entities>
    </LobSystem>
  </LobSystems>
</Model>

继续说几点其中的问题

1 SoapServerException看起来是一个普遍性的异常。因为之后的调试过程中也经常出现这一问题,估计是运行时Server端的异常客户端都反映为SoapServerException,看不到异常栈真的很不方便

2 msdn上的那位博主在各个方法中using DataContext了,但是那样写在我的环境中就会SoapServerException。。。

3 现在list确实可以看了,但是一旦点了edit(可以看见代码中已经实现了Updater),就会如下画面,杯具啊~~~~~~~~~~~

[MOSS2010]利用BCS进行数据集成(二)_第2张图片

 

哎。。。路漫漫其修远兮~~~~~~

P.S.原来Entity的结构决定了之后用BDC Explorer添加operation还是很方便的

你可能感兴趣的:(OS)