将正确的名称空间添加到Web服务xml响应

时间:2019-06-26 16:01:10

标签: xml web-services namespaces svc

我有一个SVC项目,我正在尝试按照一些规范格式化响应。 我在响应中显示的名称空间存在一些问题。 我已经基于xsd模式在C#中创建了以下元素:

 [System.Xml.Serialization.XmlTypeAttribute Namespace="http://tempuri.org/Test")]
 [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/Test", IsNullable=true)]
 public partial class BaseResponse 
  {
    private StatusCode statusCodeField;
    private ArrayOfString statusMessages;

    public StatusCode StatusCode {
        get { return this.statusCodeField;}
        set {this.statusCodeField = value;}
    }

    [System.Xml.Serialization.XmlElementAttribute(Namespace= "http://schemas.microsoft.com/2003/10/Serialization/Arrays",ElementName = "StatusMessages", IsNullable = true)]
    public ArrayOfString StatusMessages
    {
        get { return this.statusMessages;}
        set {this.statusMessages = value;}
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(IsNullable = false)]
public partial class ArrayOfString
{

    private string[] stringField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
    public string[] String
    {
        get {return this.stringField;}
        set{this.stringField = value;}
    }
}

我得到了这个答复:

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
  <BaseResponse xmlns="http://tempuri.org/Test">
     <a:StatusMessages xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
         xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
           <String xmlns="http://www.test.com/2/0">Test 123</String>
        </a:StatusMessages>
      </BaseResponse>
    </s:Body>
  </s:Envelope>

我想从“ StatusMessages”中删除“ a:”。仅在后代中需要它。

0 个答案:

没有答案