我已经看到很多SO答案,但似乎没有帮助解决我的问题。
我正在做的是从第三方调用SOAP服务,它实际上需要元素名称的前缀。
示例:
<pref:test>test</pref:test>
我使用VS中的添加服务引用创建了一个客户端。
我有一个类,我希望每个属性都有前缀。
public class WebsiteSoapHeader : System.Web.Services.Protocols.SoapHeader
{
public WebsiteSoapHeader()
{
xmlns.Add("test", "https://xxx/service");
}
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
[XmlElement(ElementName ="test",Namespace = "https://xxx/service")]
public string testprop { get; set; }
}
由于这不会手动序列化,因此只生成
<test xmlns="">test</test>