我使用的是spring ws版本1.5.8。我的回答是这样的:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      ...
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是,我的客户机(与我集成的客户机)要求我添加更多的名称空间删除,以便解析成功:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
         ...
    </soapenv:Body>
</soapenv:Envelope>

我该怎么做?

最佳答案

您可能不需要我告诉您,当文档中不使用某些名称空间时,任何需要某些名称空间声明的soap客户端都已损坏。所以我就不提了。
但是,如果您确实想这样改变响应,可以使用EndpointInterceptor,特别是SoapEndpointInterceptor。您可以连接端点拦截器as described here
您的自定义拦截器可以实现handleResponse方法,将messageContext.getResponse()强制转换为SoapMessage并添加所需的内容:

public class MyInterceptor implements SoapEndpointInterceptor {

    public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
        SoapMessage message = (SoapMessage) messageContext.getResponse();
        message.getEnvelope().addNamespaceDeclaration(....);
        return true;
    }

    // ... other methods here
}

但是,添加这样的低级名称空间声明可能会有副作用,所以要小心。

关于xml - 强制Spring Web服务将xsd namespace 添加到响应中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2813320/

10-09 05:33
查看更多