繁体   English   中英

将XML数据传递给SOAP服务困境

[英]Passing XML data to SOAP service dilemma

我昨天发布了这个问题:在遵循本书之后, 如何用Java创建SOAP Web服务http : //www.packtpub.com/java-7-jax-ws-web-services/book我设法创建了JAX-WS应用程序:

package hellows;
import javax.jws.*;
@WebService(portName = "HelloWSPort", serviceName = "HelloWSService", targetNamespace = "http://hellows/", endpointInterface = "hellows.HelloWS")
public class HelloWSImpl implements HelloWS {
    public String hello(String name) {
        // replace with your impl here
         return "Hello "+name +" Welcome to Web Services!";

    }
}

一切都很好。 但是我需要的是服务方法(即“ hello”)应该代替“ string”接受描述学生详细信息的XML文件(我已经更改了原始文件):

<?STU version="1.0"?>
<stu>    
        <id sequence="1">2354282</id>
        <date>2012-06-17T21:19:15</date>
        <student interest="food" status="newadmission">
            <id></id>
            <birthyear>2012</birthyear>
            <sex>Male</sex>
            <address>Sonata</address>
            <class>3</class>
         </student>


</stu>

然后,该服务将对其进行处理,并根据某种算法返回一个包含标志“通过” /“失败”的Java对象。

所以我的问题是:

  • 服务方法应如何接收此XML数据? 作为字符串? 或其他方式?
  • 我是否需要在config文件夹中的.wsdl和.xsd文件中描述此XML数据格式?

我已经使用AXIS2做过类似的事情。 因此,我的回答可能会给您一些希望:)

services.xml文件中:以这种方式配置您的hello操作,使其messageReceiver类的类型为org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver

<operation name="hello"> 
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> 
</operation>

然后,您可以在hello方法中处理传入的XML元素。

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.jaxen.JaxenException;

public String hello(OMElement xmlElement) {
        try {
            AXIOMXPath someXPath = new AXIOMXPath("//root/child");
        String str = ((OMElement)someXPath.selectSingleNode(node)).getText();
        } catch (JaxenException e) {
            e.printStackTrace();  
        }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM