创建没有参数名称空间的SOAP Web服务

时间:2012-08-31 14:34:58

标签: java soap jax-ws

首先,我想做的是: 我想创建一个Web服务,在收到SOAP消息时调用java函数void doSomething(ParamType value);

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <paramType>
            <elem>test</elem>
        </paramType>
    </soapenv:Body>
</soapenv:Envelope>

请注意paramType缺少的命名空间。

我创建了以下类来包含doSomething函数:

@WebService(name = "doSomethingPort", targetNamespace = "http://www.tim.org/nsClass/")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class DoSomethingImpl {

    @WebMethod(action = "http://sap.com/xi/WebService/soap1.1")
    @Oneway
    public void doSomething(
            @WebParam(name = "paramType", targetNamespace = "http://www.tim.org/nsParam/", partName = "value") 
            ParamType value) 
    {
        System.out.println("Hallo Welt");
    }
}

和以下类来保存参数:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", namespace="http://www.tim.org/nsXMLType/")
@XmlRootElement(name="paramType", namespace="http://www.tim.org/nsXMLRootElem/")
public class ParamType {

    @XmlElement(required = true)
    protected String elem;

    public String getElem() {
        return elem;
    }

    public void setElem(String value) {
        this.elem = value;
    }
}

网络服务以:

开始
Endpoint.publish( "http://localhost:8090/services", new DoSomethingImpl());

经过一些测试后的结果是: 此Web服务接受paramType具有命名空间的消息:<nsp:paramType xmlns:nsp="http://www.tim.org/nsParam/">

当我在参数上留下targetNamepace声明时,他在DoSomethingImpl类(http://www.tim.org/nsClass/)上使用targetNamespace

在那里删除命名空间会导致web服务从其包名创建命名空间。

有没有人知道如何让网络服务接受该消息? 我宁愿修复/重新配置我现有的webservice,但我会接受其他方式接受消息并调用doSomething函数。

0 个答案:

没有答案
相关问题