我在VB中编写了一个简单的Web服务(ASMX)函数:
Public Function processMessage(ByVal Messages as XMLElement) As String Dim strS as string strS = Messages.outerXML Return strS End Function
通过发送以下请求进行测试(尝试读取两条消息):
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:gps-hex-communicator"> <soap:Header/> <soap:Body> <processMessage xmlns="urn:gps-hex-communicator"> <Messages> <Message> <DeviceID>11A</DeviceID> <MessageID>1111B</MessageID> </Message> <Message> <DeviceID>22A</DeviceID> <MessageID>2222B<MessageID> </Message> </Messages> </processMessage> </soap:Body> </soap:Envelope>
得到以下回复:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <processMessageResponse xmlns="urn:gps-hex-communicator"> <processMessageResult><![CDATA[<Message xmlns="urn:gps-hex-communicator"> <DeviceID>11A</DeviceID> <MessageID>1111B</MessageID> </Message>]]></processMessageResult> </processMessageResponse> </soap:Body> </soap:Envelope>
问题是它在读取第一条消息后停止,第二条消息从未显示。我怎么能得到它?
答案 0 :(得分:0)
第二条消息上标记破损
<MessageID>2222B<MessageID>
应该是
<MessageID>2222B</MessageID>
答案 1 :(得分:0)
谢谢大家。我现在得到了答案。 XmlAnyElementAttribute有助于将所有内容都包含在内。因此asmx函数的第一行应该是:
Public Function processMessage(<XmlAnyElementAttribute()> ByVal Messages as XmlElement) As String