返回首页

嗨,

我需要一些建议,如何把一个web响应的最efficent方式,数据的数据库(结构和价值观)。它应该是迅速的,并可能脏(如没有的DAL等)。此刻,我只是玩弄一些Web服务,实施最终解决之前,比较数据质量。我的第一个方法是做一些生成的Reference.cs直接映射。对于贝蒂,我想通了,我感兴趣的数据传播广泛的Simple.AmazonECS.Item(进一步呼吁项目)属性的子类。虽然我的解决方案,在项目类的基本类型(见连招呼[属性]),它是没有好这些复杂的类型。对于一个Web服务可能会改变,我必须做的这几个服务,这将是最好的方式来获得到数据库的反应作者。我看着像xsd2db一些项目,但没有为Web服务架构(从WSDL中提取)工作。必须有一个简单的方法,从一个Web服务的XML架构,数据库架构...

PS:这可能是问题的一部分:所有的类都从Object继承!我认为这是没有实体框架支持,对不对?

有什么建议?


// This ist the auto generated reference.cs of the Amazon Webservice 

// http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl



namespace Simple.Amazon.ECS

{

    // [...] Enumerations, Classes and other stuff

    

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]

    [System.SerializableAttribute]

    [System.Diagnostics.DebuggerStepThroughAttribute]

    [System.ComponentModel.DesignerCategoryAttribute("code")]

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webservices.amazon.com/AWSECommerceService/2009-07-01")]

    public partial class Image : object, System.ComponentModel.INotifyPropertyChanged

    {

        #region Fields

 

        private string uRLField;

        //[...]



        #endregion Fields

 

        #region Events

 

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

 

        #endregion Events

 

        #region Properties

 

        [System.Xml.Serialization.XmlElementAttribute(Order=0)]

        [Column(Name = "URL", Storage = "uRLField", AutoSync = AutoSync.OnInsert, IsPrimaryKey= true)]

        [DataMember(Order = 0)]

        public string URL

        {

            get {

                return this.uRLField;

            }

            set {

                this.uRLField = value;

                this.RaisePropertyChanged("URL");

            }

        }

        //[...]



        #endregion Properties

 

        #region Methods

        

        protected void RaisePropertyChanged(string propertyName)

		//[...]



        #endregion Methods

    }

    

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]

    [System.SerializableAttribute]

    [System.Diagnostics.DebuggerStepThroughAttribute]

    [System.ComponentModel.DesignerCategoryAttribute("code")]

    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://webservices.amazon.com/AWSECommerceService/2009-07-01")]

    // my approach

    //[Table(Name = "dbo.AmazonItems")]

    //[DataContract()]

    public partial class Item : object, System.ComponentModel.INotifyPropertyChanged

    {

        #region Fields

 

        private string aSINField;

        private Image largeImageField;

        private ItemAttributes itemAttributesField;

		//[...]



        #endregion Fields

 

        #region Events

 

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

 

        #endregion Events

 

        #region Properties

 

        [System.Xml.Serialization.XmlElementAttribute(Order=0)]

        // my approach - this works for the basic type

        //[Column(Name = "ASIN",Storage="aSINField", AutoSync = AutoSync.OnInsert, IsPrimaryKey = true)]

        //[DataMember(Order=0)]

        public string ASIN

        {

            get {

                return this.aSINField;

            }

            set {

                this.aSINField = value;

                this.RaisePropertyChanged("ASIN");

            }

        }

 

        [System.Xml.Serialization.XmlElementAttribute(Order=10)]

        // my approach - this crashes - unknown sql type - the data i am inteseted in

        //[Column(Name = "ItemAttributes", Storage = "itemAttributesField", AutoSync = AutoSync.OnInsert, DbType="SQL_VARIANT")]

        //[DataMember(Order = 10)]

        public ItemAttributes ItemAttributes

        {

            get {

                return this.itemAttributesField;

            }

            set {

                this.itemAttributesField = value;

                this.RaisePropertyChanged("ItemAttributes");

            }

        }

 

        [System.Xml.Serialization.XmlElementAttribute(Order=8)]

        // my approach - this crashed to - complex type

        //[Column(Name = "LargeImage", Storage = "largeImageField", AutoSync = AutoSync.OnInsert)]

        //[DataMember(Order = 8)]

        public Image LargeImage

        {

            get {

                return this.largeImageField;

            }

            set {

                this.largeImageField = value;

                this.RaisePropertyChanged("LargeImage");

            }

        }

 

        //[...] more Classes, Events, ...



 



// well, here is what i am doing in Main()



// create a WCF Amazon ECS client

BasicHttpBinding binding		= new BasicHttpBinding(BasicHttpSecurityMode.Transport);

binding.MaxReceivedMessageSize	= int.MaxValue;

AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(

    binding,

    new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

 

// add authentication to the ECS client

client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

 

// prepare an ItemSearch request

ItemSearchRequest request1	= new ItemSearchRequest();

 

request1.SearchIndex			= "All";

request1.DeliveryMethod = DeliveryMethod.Ship;

request1.MerchantId = "All";

request1.Condition = Condition.All;

request1.ResponseGroup = new string[] {"Large"};

request1.Keywords = "test";

 

// prepare the search

ItemSearch itemSearch = new ItemSearch();

itemSearch.AssociateTag = "";

// batch the two requests together

itemSearch.Request = new ItemSearchRequest[] { request1, request2 };

itemSearch.AWSAccessKeyId = accessKeyId;            

            

// issue the ItemSearch request

ItemSearchResponse response = client.ItemSearch(itemSearch);

 

// issue the DataContext on SQL 2008 R2 server

DataContext db = new DataContext(@"Data Source=./;Database=test;Integrated Security=SSPI;");

 

// a Table of the Simple.ECS.Amazon.Item class

Table<item> it = db.GetTable<item>();

 

// drop the test DB

db.DeleteDatabase();

// and recreate the structure it to see if it works

// this ist where errors occure 

// for unknown sql types (complex types like Simple.Amazon.ECS.Image)

db.CreateDatabase();

 

foreach (var responses in response.Items)

{

    foreach (var item in responses.Item)

    {

        it.InsertOnSubmit(item);

    }

}

db.SubmitChanges();

db.Connection.Close();                                                

</item></item>

回答

评论会员: 时间:2
G