我正在尝试在 C# 中手动构造一个 SOAP 信封。我最初通过 StringBuilder 构建它并通过 LoadXml 方法将其添加到 XmlDocument 的路线。但是,在执行时,我遇到了以下异常:
System.Xml.XmlException : ':' 字符,十六进制值 0x3A,不能包含在名称中。第 1 行,位置 200。
我要创建的信封是:
<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:Header>
<wsrp:path
soap:actor="http://schemas.xmlsoap.org/soap/actor/next"
soap:mustUnderstand="1"
xmlns:wsrp="http://schemas.xmlsoap.org/rp">
<wsrp:action>
http://abcd.com/Webservices
</wsrp:action>
<wsrp:to>
http://abcd.com/Webservices.asmx
</wsrp:to>
<wsrp:id>
uuid:aaaaa0a7-9e46-432b-8f1b-35037077601f
</wsrp:id>
</wsrp:path>
<wsu:Timestamp
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<wsu:Created>
2012-11-30T10:38:13z
</wsu:Created>
<wsu:Expires>
2012-11-30T11:38:13z
</wsu:Expires>
</wsu:Timestamp>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
<wsse:UsernameToken
wsu:Id="SecurityToken-00c26e1a-3b3b-400f-a99a-3aa54cf8c8ff"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<wsse:Username>username</wsse:Username>
<wsse:Password Type="wsse:PasswordText">password</wsse:Password>
<wsse:Nonce>NBzqolcwIZrAOYw1vLyucDM3sQQ=</wsse:Nonce>
<wsu:Created>2012-11-30T10:38:13z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<MethodName xmlns="http://abcd.com/Webservices">
<ValueField>Ford</ValueField>
</MethodName>
</soap:Body>
</soap:Envelope>
我很难理解为什么编译器对“:”不满意。有没有更好的方法来做到这一点/我在这里做错了什么?