How to set xsi attribute using built in .net SoapHttpClient

Edit So literally like 5 minutes after I posted this, I figured out my answer. Just posting here in case anyone else needs this help. I had to set the Item within items to service. Something like this

 CartItem[] items = { new CartItem() }; //right here is the item, there's some way I need to be able to set the xsi type of items[0].item to Service. items[0].ID = itemId; //549 items[0].IDSpecified = false; items[0].Quantity = 1; items[0].ActionSpecified = false; Service svc = new Service(); svc.ID = itemId.ToString(); svc.OnlinePrice = amount; items[0].Item = svc; req.CartItems = items; 

So here is my issue, I need to generate xml that looks something like this

<CartItems> <CartItem> <Quantity>1</Quantity> <Item xsi:type="Service"> <ID>000123</ID> </Item> </CartItem> </CartItems> 

I have a bunch of C# classes I generated from their wsdl file using the wsdl.exe thing MS provides. The issue I have is I'm not 100% sure how to set that xsi type attribute. When I look at the actual item class in cart item, I don't see any way to set the xsi type. Here's the relevant code on setting the item

CartItem[] items = { new CartItem() }; CartItem citem = new CartItem(); //right here is the item, there's some way I need to be able to set the xsi type of items[0].item to Service. items[0].ID = itemId; //549 items[0].IDSpecified = false; items[0].Quantity = 1; items[0].ActionSpecified = false; req.CartItems = items; 

The last thing is, in investigating the generated classes. I was looking at the cart item object, and there is no way to set a service in it, however, right below it there is a partial class which looks like it has what I need, I'm just not sure how to implement it. This generated code is pushing the limits of my OOP knowledge. Here's the cart item class and the partial class just for reference. A side note, the thing I think I need is at the bottom. Thanks,

/// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.81.0")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://ift.tt/1IGhA63;)] public partial class CartItem : MBObject { private Item itemField; private decimal discountAmountField; private Appointment[] appointmentsField; private int[] enrollmentIDsField; private int[] classIDsField; private long[] courseIDsField; private long[] visitIDsField; private long[] appointmentIDsField; private ActionCode actionField; private bool actionFieldSpecified; private System.Nullable<int> idField; private bool idFieldSpecified; private System.Nullable<int> quantityField; private bool quantityFieldSpecified; /// <remarks/> public Item Item { get { return this.itemField; } set { this.itemField = value; } } /// <remarks/> public decimal DiscountAmount { get { return this.discountAmountField; } set { this.discountAmountField = value; } } /// <remarks/> public Appointment[] Appointments { get { return this.appointmentsField; } set { this.appointmentsField = value; } } /// <remarks/> public int[] EnrollmentIDs { get { return this.enrollmentIDsField; } set { this.enrollmentIDsField = value; } } /// <remarks/> public int[] ClassIDs { get { return this.classIDsField; } set { this.classIDsField = value; } } /// <remarks/> public long[] CourseIDs { get { return this.courseIDsField; } set { this.courseIDsField = value; } } /// <remarks/> public long[] VisitIDs { get { return this.visitIDsField; } set { this.visitIDsField = value; } } /// <remarks/> public long[] AppointmentIDs { get { return this.appointmentIDsField; } set { this.appointmentIDsField = value; } } /// <remarks/> public ActionCode Action { get { return this.actionField; } set { this.actionField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool ActionSpecified { get { return this.actionFieldSpecified; } set { this.actionFieldSpecified = value; } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] public System.Nullable<int> ID { get { return this.idField; } set { this.idField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool IDSpecified { get { return this.idFieldSpecified; } set { this.idFieldSpecified = value; } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] public System.Nullable<int> Quantity { get { return this.quantityField; } set { this.quantityField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool QuantitySpecified { get { return this.quantityFieldSpecified; } set { this.quantityFieldSpecified = value; } } } /// <remarks/> [System.Xml.Serialization.XmlIncludeAttribute(typeof(Tip))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Product))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Package))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(Service))] [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.81.0")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://ift.tt/1IGhA63;)] public partial class Item : MBObject { } 

by andrewsmd87 via /r/csharp

Leave a Reply