Hey guys,
I need some advice on how to put a data of a webservice response the most efficent way into a database (structure and values). It should be quick and may be dirty (e.g. no DAL, etc.). At the moment i am just playing around with some webservices, comparing data quality before implementing a final solution. My first approach was to do some mapping in the generated Reference.cs directly. For a pitty i figured out, that the data i am interested in is spread widely in subclasses of the Simple.AmazonECS.Item (further called Item) properties. While my solution works on basic types in the Item class (see the uncommented [Attributes]), it is no good for these complex types. For a webservice may change and i have to do this with several services, what would be the best way to get the respons into a database. I looked at some projects like xsd2db, but none worked for the webservices schema (extracted from wsdl). There must be an easy way to get from a webservice xml schema to a database schema...
PS: this may be part of the problem: all classes are inherited from object! i think this is not supported by the entity framework, right?
Any suggestions?
namespace Simple.Amazon.ECS
{
[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")]
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)]
public string ASIN
{
get {
return this.aSINField;
}
set {
this.aSINField = value;
this.RaisePropertyChanged("ASIN");
}
}
[System.Xml.Serialization.XmlElementAttribute(Order=10)]
public ItemAttributes ItemAttributes
{
get {
return this.itemAttributesField;
}
set {
this.itemAttributesField = value;
this.RaisePropertyChanged("ItemAttributes");
}
}
[System.Xml.Serialization.XmlElementAttribute(Order=8)]
public Image LargeImage
{
get {
return this.largeImageField;
}
set {
this.largeImageField = value;
this.RaisePropertyChanged("LargeImage");
}
}
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"));
client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));
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";
ItemSearch itemSearch = new ItemSearch();
itemSearch.AssociateTag = "";
itemSearch.Request = new ItemSearchRequest[] { request1, request2 };
itemSearch.AWSAccessKeyId = accessKeyId;
ItemSearchResponse response = client.ItemSearch(itemSearch);
DataContext db = new DataContext(@"Data Source=./;Database=test;Integrated Security=SSPI;");
Table<item> it = db.GetTable<item>();
db.DeleteDatabase();
db.CreateDatabase();
foreach (var responses in response.Items)
{
foreach (var item in responses.Item)
{
it.InsertOnSubmit(item);
}
}
db.SubmitChanges();
db.Connection.Close();
</item></item>