XmlTypeAttribute不改变类型的名称 [英] XmlTypeAttribute does not change name of type
问题描述
我正在使用WSE3调用Web服务的项目。原本使用VS2005产生的类型已被修改过的时间。现在,我需要改变的SOAP消息的类型的名称。我推测,应该使用XmlTypeAttribute来完成,但这并不影响类型名称。作为一个实验,我用XmlElementAttribute上类的属性,并没有改变该属性生成的元素的名称。生成的对象已使用部分类扩展。
SOAP的类型遇到线路为地址。我不知道为什么XmlTypeAttribute不影响它,或者它为什么整个小写来了。
这是什么,我可能是做错了,或者有更好的方式来实现这一目标的思考?
References.cs:
[系统。codeDom.Compiler.Generated codeAttribute(的System.Xml,2.0.50727.1434)
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(code)
[System.Xml.Serialization.XmlTypeAttribute(类型名=MyAddress,命名空间=http://sample.com/transaction)
// ^ - 皂typenamed地址,而不是MyAddress
公共部分类地址
{
私人字符串address1Field;
私人字符串address2Field;
私人字符串[] jurisdictionsField;
私人的System.DateTime resolvedDateField;
私人布尔resolvedDateFieldSpecified;
///<备注/>
[System.Xml.Serialization.XmlElementAttribute(MyAddress1,表= System.Xml.Schema.XmlSchemaForm.Unqualified)
// ^ - 名为MyAddress1预期SOAP元素
公共虚拟字符串地址1
{
得到 {
返回this.address1Field;
}
组 {
this.address1Field =价值;
}
}
///<备注/>
[System.Xml.Serialization.XmlElementAttribute(地址2,表= System.Xml.Schema.XmlSchemaForm.Unqualified)
公共虚拟字符串地址2
{
得到 {
返回this.address2Field;
}
组 {
this.address2Field =价值;
}
}
}
Address.cs:
公共部分类地址
{
私人诠释身份证;
公共虚拟INT标识
{
{返回ID; }
集合{ID =价值; }
}
}
[XmlType将]
更改的名称复杂类型
的模式。它并不在XML改变元素名称
使用 [的XmlElement(NAME =MyAddress,命名空间=你的命名空间)]
代替。
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 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(Name="MyAddress", Namespace="your namespace")]
instead.
这篇关于XmlTypeAttribute不改变类型的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!