我正在开发一个使用 WSE3 调用 Web 服务的项目。最初使用 VS2005 生成的类型已随着时间的推移进行了修改。现在,我需要更改 SOAP 消息中的类型名称。我认为应该使用 XmlTypeAttribute 来完成,但这不会影响类型名称。作为实验,我在该类的属性上使用了 XmlElementAttribute,这确实更改了为该属性生成的元素的名称。生成的对象已使用部分类进行了扩展。
SOAP 类型作为“地址”通过网络传输。我不确定为什么 XmlTypeAttribute 不影响它,或者为什么它会遇到小写。
关于我可能做错了什么的想法,或者实现目标的更好方法?
引用文献.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;
}
}
}
地址.cs:
public partial class Address
{
private int id;
public virtual int Id
{
get { return id; }
set { id = value; }
}
}
最佳答案
[XmlType]
更改架构中 complexType
的名称。它不会更改 XML 中的元素名称。
改用[XmlElement(ElementName="MyAddress", Namespace="your namespace")]
。
关于.net - XmlTypeAttribute 不更改类型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1579982/