2

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

<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 类上的 targetNamespace ( http://www.tim.org/nsClass/)

删除那里的命名空间会导致 web 服务从他的包名创建一个命名空间。

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

4

0 回答 0