首页 文章

通过ASMX web servcie函数读取SOAP XML

提问于
浏览
1

我在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>

问题是它在读取第一条消息后停止,第二条消息从未显示 . 我怎么才能得到它?

2 回答

  • 0

    谢谢大家 . 我现在得到了答案 . XmlAnyElementAttribute有助于获取所有内容 . 因此asmx函数的第一行应该是:

    Public Function processMessage(<XmlAnyElementAttribute()> ByVal Messages as XmlElement) As String
    
  • 0

    第二条消息上有一个损坏的标记

    <MessageID>2222B<MessageID>
    

    应该是

    <MessageID>2222B</MessageID>
    

相关问题