I am digesting a web serivce from Amazon.Com. I have the following
class which was autogenerated by VS.NET when I created a Web Reference
to http://webservices.amazon.com/AWSECo...ceService.wsdl
AmazonWebServic e.com.amazon.we bservices.Item
As you can see from the code snippets below it has public member
variables rather than public Properties. When I use <%#
DataBinder.Eval (Container.Data Item, "ASIN") %> syntax in Repeater1 in
my aspx page I get the following error.
[HttpException (0x80004005): DataBinder.Eval :
'AmazonWebServi ce.com.amazon.w ebservices.Item ' does not contain a
property with the name ASIN.]
System.Web.UI.D ataBinder.GetPr opertyValue(Obj ect container, String
propName)
System.Web.UI.D ataBinder.Eval( Object container, String[]
expressionParts )
System.Web.UI.D ataBinder.Eval( Object container, String expression)
ASP.SearchForm_ aspx.__DataBind __control8(Obje ct sender, EventArgs e)
in c:\inetpub\wwwr oot\AmazonWebSe rvice\SearchFor m.aspx:33
System.Web.UI.C ontrol.OnDataBi nding(EventArgs e)
System.Web.UI.C ontrol.DataBind ()
System.Web.UI.C ontrol.DataBind ()
System.Web.UI.W ebControls.Repe ater.CreateItem (Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.W ebControls.Repe ater.CreateCont rolHierarchy(Bo olean
useDataSource)
System.Web.UI.W ebControls.Repe ater.OnDataBind ing(EventArgs e)
System.Web.UI.W ebControls.Repe ater.DataBind()
AmazonWebServic e.Web.SearchFor m.Button1_Click (Object sender, EventArgs
e) in c:\inetpub\wwwr oot\amazonwebse rvice\searchfor m.aspx.cs:83
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain()
If I add a property to the Item class called ASINP, which encapsulates
ASIN member variable, and I use <%#
DataBinder.Eval (Container.Data Item, "ASINP") %> syntax in Repeater1 on
my aspx then everything works fine. Since the Item class is
autogenerated I do not want to have to add Properties in every
autogenerated class because I have about 40 auto generated classes.
How can I reference the memeber variable ASIN in the aspx page, or any
other memeber variable in that class.
Please see the code snippets below if you have questions.
Thanks,
Chris Gastin
CODE SNIPPETS:
////////////////////////////////////////////////////////////////////////////////////////////////////
// asp:Repeater
///////////////////////////////////////////////////////////////////////////////////////////////////
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate >
<table border=1>
<tr>
<td>Results:</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td bgcolor="LightG rey">
<%# DataBinder.Eval (Container.Data Item, "ASIN") %>
</td>
</tr>
</ItemTemplate>
<AlternatingIte mTemplate>
<tr>
<td bgcolor="Yellow ">
<%# DataBinder.Eval (Container.Data Item, "ASIN") %>
</td>
</tr>
</AlternatingItem Template>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater>
////////////////////////////////////////////////////////////////////////////////////////////////////
// Button Click Event
///////////////////////////////////////////////////////////////////////////////////////////////////
private void Button1_Click(o bject sender, System.EventArg s e)
{
AWSECommerceSer vice svc = new AWSECommerceSer vice();
ItemSearchReque st itemSearchReque st = new ItemSearchReque st();
itemSearchReque st.Keywords = TextBox1.Text;
itemSearchReque st.SearchIndex = DropDownList1.S electedValue;
itemSearchReque st.MerchantId = "All";
itemSearchReque st.ResponseGrou p = new string[]{"Large"};
ItemSearch search = new ItemSearch();
search.Subscrip tionId =
ConfigurationSe ttings.AppSetti ngs["SubscriptionId "];
search.Request = new ItemSearchReque st[]{itemSearchRequ est};
IAsyncResult result = svc.BeginItemSe arch(search,nul l,null);
ItemSearchRespo nse searchResponse = svc.EndItemSear ch(result);
Repeater1.DataS ource = searchResponse. Items[0].Item;
Repeater1.DataB ind();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Item Class
///////////////////////////////////////////////////////////////////////////////////////////////////
/// <remarks/>
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="http://webservices.ama zon.com/AWSECommerceSer vice/2004-10-19")]
public class Item {
/// <remarks/>
public string ASIN;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("Error",
IsNullable=fals e)]
public ErrorsError[] Errors;
/// <remarks/>
public string DetailPageURL;
/// <remarks/>
public string SalesRank;
/// <remarks/>
public Image SmallImage;
/// <remarks/>
public Image MediumImage;
/// <remarks/>
public Image LargeImage;
/// <remarks/>
public ItemAttributes ItemAttributes;
/// <remarks/>
public OfferSummary OfferSummary;
/// <remarks/>
public Offers Offers;
/// <remarks/>
public VariationSummar y VariationSummar y;
/// <remarks/>
public Variations Variations;
/// <remarks/>
public CustomerReviews CustomerReviews ;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("EditorialRev iew",
IsNullable=fals e)]
public string[] EditorialReview s;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("SimilarProdu ct",
IsNullable=fals e)]
public SimilarProducts SimilarProduct[] SimilarProducts ;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("SimilarBusin ess",
IsNullable=fals e)]
public SimilarBusiness esSimilarBusine ss[] SimilarBusiness es;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("Accessory" ,
IsNullable=fals e)]
public AccessoriesAcce ssory[] Accessories;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("Disc",
IsNullable=fals e)]
public TracksDisc[] Tracks;
/// <remarks/>
public BrowseNodes BrowseNodes;
/// <remarks/>
[System.Xml.Seri alization.XmlAr rayItemAttribut e("ListmaniaLis t",
IsNullable=fals e)]
public ListmaniaListsL istmaniaList[] ListmaniaLists;
/// <remarks/>
public SearchInside SearchInside;
/// <remarks/>
public PromotionalTag PromotionalTag;
}