以下是我的 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: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>
有什么办法可以添加这个前缀吗?