I'm working on a project that calls a web service using WSE3. The types originally generated using VS2005 have been modified over time. Now, I need to change the name of the type in the SOAP message. I gather that should be done using XmlTypeAttribute, but that does not affect the type name. As an experiment, I used XmlElementAttribute on a property of that class, and that did change the name of the element generated for that property. The generated object has been extended using partial classes.
The SOAP type comes across the wire as "address". I'm not sure why XmlTypeAttribute is not affecting it, or why it is coming across lower case.
Thoughts on what I might be doing wrong, or a better way to accomplish the goal?
References.cs:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1434")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName = "MyAddress", Namespace = "http://sample.com/transaction")]
// ^-- Soap typenamed "address", not "MyAddress"
public partial class Address
{
private string address1Field;
private string address2Field;
private string[] jurisdictionsField;
private System.DateTime resolvedDateField;
private bool resolvedDateFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("MyAddress1", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
// ^--- SOAP element named "MyAddress1" as expected
public virtual string Address1
{
get {
return this.address1Field;
}
set {
this.address1Field = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("address2", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public virtual string Address2
{
get {
return this.address2Field;
}
set {
this.address2Field = value;
}
}
}
Address.cs:
public 开发者_StackOverflow社区partial class Address
{
private int id;
public virtual int Id
{
get { return id; }
set { id = value; }
}
}
[XmlType]
changes the name of the complexType
in the schema. It does not change element names in the XML.
Use [XmlElement(ElementName="MyAddress", Namespace="your namespace")]
instead.
精彩评论