【发布时间】:2017-11-27 12:57:41
【问题描述】:
我一直在使用 C# 处理 SOAP 请求/响应。我得到了请求和响应格式应该如何。我已经成功创建了一个发送请求的[WebMethod],我可以从中检索XML 响应。问题是我得到的响应是这样的
<soapenv:Header>
<v1:ResultStatus xmlns:v1="http://group.com/contract/vho/header/v1">
<bf:Timestamp xmlns:bf="http://docs.oasis-open.org/wsrf/bf-2">27-Nov-17 1:42:24 PM</bf:Timestamp>
<bf:ErrorCode xmlns:bf="http://docs.oasis-open.org/wsrf/bf-2">OK</bf:ErrorCode>
<bf:Description xmlns:bf="http://docs.oasis-open.org/wsrf/bf-2">Integration Id cannot be retrieved for this user</bf:Description>
<v11:Message xmlns:v11="http://group.com/schema/common/v1">FAILURE</v11:Message>
</v1:ResultStatus>
</soapenv:Header>
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<v1:CheckAuthenticationCredentialVBMResponse xmlns:v1="http://group.com/schema/vbm/identity/authentication-credential/v1">
<v1:AuthenticationCredentialVBO actionCode="ADD">
<v11:IDs xmlns:v11="http://group.com/schema/common/v1">
<v11:ID schemeName="Authentication Credential ID">5535</v11:ID>
</v11:IDs>
</v1:CheckAuthenticationCredentialVBMResponse>
</SOAP-ENV:Body>
当我尝试使用XmlDocument xmldoc.GetElementsByTagName("bf:ErrorCode"); 或XmlDocument xmldoc.GetElementsByTagName("v11:Message"); 读取它时,它会将: 视为特殊字符,因此无法继续执行,抛出此异常:
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
我试图找到一些关于此的文档,但我似乎找不到类似的东西。有人可以帮忙吗?
如果需要更多信息,请发表评论。
【问题讨论】:
-
我也陷入了这个陷阱,SOAP 不是 xml,非常相似但显然不遵循其规则,因此无法使用 xml 解析器进行解析,您需要使用 SoapClient 类
-
您可能希望添加更多响应消息以显示已定义命名空间“v1”、“v11”和“bf”。了解“xmldoc”的数据类型也会有所帮助,以便有人可以帮助向您展示处理命名空间的正确 API。
-
@Michael 好的,我会对此进行研究。如果您有与此相关的任何链接,请分享。
-
@Nathan 我将使用非常短的正文版本来编辑帖子,并声明 xmldoc。谢谢你的建议。
-
@Noel 在 google 中找到它:msdn.microsoft.com/en-us/library/ms819935.aspx