通过 ASMX web servcie 函数读取 SOAP XML

发布于 2025-01-04 23:52:17 字数 1698 浏览 5 评论 0原文

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

问题是它在读取第一条消息后停止,而第二条消息永远不会显示。我怎样才能得到它?

I wrote a simple web service (ASMX) function in VB:

Public Function processMessage(ByVal Messages as XMLElement) As String  
    Dim strS as string
    strS = Messages.outerXML
    Return strS
End Function  

And test by sending the following request (attempt to read two messages):

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

And get the following response:

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

The problem is that it stops after reading first message and second one never shows up. How can I get it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北斗星光 2025-01-11 23:52:18

第二条消息上的标签已损坏,

<MessageID>2222B<MessageID>

可能应该是

 <MessageID>2222B</MessageID>

You have a broken tag on the second message

<MessageID>2222B<MessageID>

should probably be

 <MessageID>2222B</MessageID>
已下线请稍等 2025-01-11 23:52:18

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

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

Thanks everybody. I got the answer now. The XmlAnyElementAttribute helps to get everything in. So the first line of asmx function should be:

Public Function processMessage(<XmlAnyElementAttribute()> ByVal Messages as XmlElement) As String   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文