SOAP Body

 SOAP Body

作者:w3pop.com 翻译/整理:w3pop.com
<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>

The mandatory SOAP Body element contains the actual SOAP message.
具有强制性的SOAP主体元素包含了现行的SOAP信息。


The SOAP Body Element
Soap主体元素

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.
所要求的SOAP主体元素包含了用于信息终端的现行SOAP信息。

Immediate child elements of the SOAP Body element may be namespace-qualified. SOAP defines one element inside the Body element in the default namespace ("http://www.w3.org/2001/12/soap-envelope"). This is the SOAP Fault element, which is used to indicate error messages.
直接的SOAP主体元素的子元素可能是有资格获得命名空间(name-space)的。SOAP以默认的命名空间定义了("http://www.w3.org/2001/12/soap-envelope")主体元素内的一个元素。这是SOAP用来显示错误信息的“错误元素”。

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
   <m:GetPrice xmlns:m="http://www.w3schools.com/prices">
      <m:Item>Apples</m:Item>
   </m:GetPrice>
</soap:Body>
</soap:Envelope>

The example above requests the price of apples. Note that the m:GetPrice and the Item elements above are application-specific elements. They are not a part of the SOAP standard.
上面举的是请求苹果价格的例子。注意,上面的m:GetPrice和项目元素都是详细的应用程序(application-specific)元素。它们不是SOAP标准的一部分。

A SOAP response could look something like this:
SOAP响应如下:

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
   <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
      <m:Price>1.90</m:Price>
   </m:GetPriceResponse>

</soap:Body>
</soap:Envelope>
<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要接收SOAP消息并获取SOAP Body元素值,您可以使用Java中的SOAP API。以下是一个示例代码片段,说明如何使用SOAP API读取SOAP消息中的Body元素值: ```java // 创建一个SOAP消息的解析器 MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); // 从SOAP消息中获取SOAP Body元素 SOAPBody soapBody = soapMessage.getSOAPBody(); // 获取SOAP Body元素的第一个子元素 Node firstChild = soapBody.getFirstChild(); // 获取SOAP Body元素的值 String bodyValue = firstChild.getTextContent(); ``` 在此示例中,我们首先创建一个SOAP消息解析器,然后使用它来创建一个新的SOAP消息。接下来,我们从SOAP消息中获取SOAP Body元素,并使用它的getFirstChild()方法获取第一个子元素。最后,我们使用子元素的getTextContent()方法获取SOAP Body元素的值。 请注意,此示例仅适用于SOAP消息已经被解析到SOAPMessage对象中。如果您需要从传入的SOAP消息中获取SOAP Body元素,请使用类似于以下代码的方法: ```java // 获取传入的HTTP请求 HttpServletRequest request = ...; // 获取请求中的输入流 InputStream input = request.getInputStream(); // 创建一个SOAP消息解析器 MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(null, input); // 从SOAP消息中获取SOAP Body元素 SOAPBody soapBody = soapMessage.getSOAPBody(); // 获取SOAP Body元素的第一个子元素 Node firstChild = soapBody.getFirstChild(); // 获取SOAP Body元素的值 String bodyValue = firstChild.getTextContent(); ``` 在此示例中,我们首先获取传入的HTTP请求,并从中获取输入流。接下来,我们使用输入流创建一个新的SOAP消息解析器,并将其用于创建新的SOAP消息。接下来,我们从SOAP消息中获取SOAP Body元素,并使用它的getFirstChild()方法获取第一个子元素。最后,我们使用子元素的getTextContent()方法获取SOAP Body元素的值。 请注意,此示例仅适用于传入的HTTP请求包含SOAP消息。如果请求不包含SOAP消息,则必须使用其他方法来解析请求中的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值