如何在soap消息中的top元素中添加前缀

时间:2013-07-12 00:22:17

标签: c# .net web-services soap asmx

以下是我的asmx网络服务

 [WebService(Namespace = "http://test.com/test")]
 [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
 public class Pilot : System.Web.Services.WebService
 {
    [WebMethod]
    public Attribute[] IsPilotUser(Data Data)
    {
          //logic here
    }

 }

[Serializable()]
public class Data
{
    public string HumanNo
    {
        get;
        set;
    }
}


[Serializable()]
[System.Xml.Serialization.XmlRoot("Attribute")]
public class Attribute
{

    [System.Xml.Serialization.XmlElement(Namespace="http://test.com/test")]
      public string Name = "UserResult";

   [System.Xml.Serialization.XmlElement(Namespace="http://test.com/test")]
    public string value
    {
       get;
       set;
    }

    [System.Xml.Serialization.XmlNamespaceDeclarations]
    public System.Xml.Serialization.XmlSerializerNamespaces xmlns = new   System.Xml.Serialization.XmlSerializerNamespaces();

    public Attribute()
    {
        xmlns.Add("pf", "http://test.com/test");
        xmlns.Add("pf", "http://test.com/test");
    }

}

当客户端尝试使用它时,这是当前的soap响应消息。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <IsPilotUserResponse xmlns="http://test.com/test">
      <IsPilotUserResult>
        <pf:Attribute xmlns:pf="http://test.com/test">
          <pf:Name>UserResult</pf:Name>
          <pf:value>i am value</pf:value>
        </pf:Attribute>
      </IsPilotUserResult>
    </IsPilotUserResponse>
  </soap:Body>
</soap:Envelope>

如果您注意到前两个元素没有前缀“pf:”

<IsPFMPilotUserResponse xmlns="http://test.com/test">
    <IsPFMPilotUserResult>

有什么办法可以添加这个前缀吗?

0 个答案:

没有答案