Java 和 Soap Web 服务 |为什么命名空间前缀在迁移时会自动从 ns2 更改为 ns4?

Java and Soap Web Service | Why do namespaces prefix changes automatically from ns2 to ns4 on migration?

提问人:fatherazrael 提问时间:5/4/2021 最后编辑:fatherazrael 更新时间:5/4/2021 访问量:1065

问:

Soap Service Migration 更改 Web 服务响应的命名空间前缀:

早些时候是:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns2:GetProjectsResponseType 
xmlns="http://psi.eto.com/tsb/schema/common" 
xmlns:ns2="http://tsb.eto.com/terp/ws/schema" 
xmlns:ns3="http://psi.eto.com/tsb/schema/project" 
xmlns:ns4="http://tsb.eto.com/tsb" 
xmlns:ns5="http://psi.eto.com/tsb/schema/customer" 
xmlns:ns6="http://psi.eto.com/tsb/schema/servicecontract" 
xmlns:ns7="http://psi.eto.com/tsb/schema/task" 
xmlns:ns8="http://psi.eto.com/tsb/schema/offering" 
xmlns:ns9="http://psi.eto.com/kil/system/message">

现在它更改为:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns2:GetProjectsResponseType 
xmlns="http://psi.eto.com/tsb/schema/common" 
xmlns:ns2="http://tsb.eto.com/terp/ws/schema" 
xmlns:ns3="http://psi.eto.com/tsb/schema/servicecontract"  <------
xmlns:ns4="http://tsb.eto.com/tsb" 
xmlns:ns5="http://psi.eto.com/tsb/schema/customer" 
xmlns:ns6="http://psi.eto.com/tsb/schema/project" <-----
xmlns:ns7="http://psi.eto.com/tsb/schema/task" 
xmlns:ns8="http://psi.eto.com/tsb/schema/offering" 
xmlns:ns9="http://psi.eto.com/kil/system/message">

此命名空间中发生更改的原因可能是什么?

@WebService(targetNamespace = "http://tsb.eto.com/terp/ws/v2", name = "Terp-v2")
@XmlSeeAlso({com.eto.psi.tsb.schema.common.ObjectFactory.class, 
    com.eto.psi.tsb.schema.offering.ObjectFactory.class, 
    com.eto.psi.kil.system.message.ObjectFactory.class, 
    com.eto.tsb.terp.ws.schema.ObjectFactory.class, 
    com.eto.psi.tsb.schema.task.ObjectFactory.class, 
    com.eto.psi.tsb.schema.servicecontract.ObjectFactory.class, 
    com.eto.psi.tsb.schema.project.ObjectFactory.class, 
    com.eto.tsb.tsb.ObjectFactory.class, 
    com.eto.psi.tsb.schema.customer.ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface TerpV2 {

   @WebMethod(operationName = "GetServiceContracts")
   @WebResult(name = "GetServiceContractsResponseType", targetNamespace = "http://tsb.eto.com/terp/ws/schema", partName = "payload")
   public com.eto.tsb.terp.ws.schema.GetServiceContractsResponseType getServiceContracts(
       @WebParam(partName = "payload", name = "GetServiceContractsType", targetNamespace = "http://tsb.eto.com/terp/ws/schema")
       com.eto.tsb.terp.ws.schema.GetServiceContractsType payload
    ) throws TerpServiceFault;

    and so on all operations are defined (without above sequence)

对于所有 ns,Package Info 都有如下内容:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://psi.eto.com/tsb/schema/servicecontract", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.eto.psi.tsb.schema.servicecontract;

没有命名空间和操作名称映射的此类列表。尝试删除 Xmlnsfor 限定,但没有理想的结果。

原因:客户的旧代码尚未准备好更改,并且对命名空间进行了硬编码。

Java Web Services SOAP 命名空间

评论

1赞 Thomas Kläger 5/4/2021
您必须了解命名空间的含义由其命名空间名称(部件)定义。命名空间前缀(部件)提供的唯一功能是命名空间名称的方便快捷方式,并且本身不具有隐含含义。因此,随意更改命名空间前缀是完全合法的。http://psi.eto.com/tsb/schema/servicecontractns2
0赞 fatherazrael 5/4/2021
@ThomasKläger:客户未更改客户端代码。他想要相同的命名空间,因为他因此遇到了许多问题。我不确定他为什么在 10 年前对其进行硬编码。但技术债务是存在的。找到这个:也尝试一下。stackoverflow.com/questions/28538896/.......任何更多的帮助将不胜感激。

答:

2赞 Thomas Kläger 5/4/2021 #1

您可以使用包信息来完全修复命名空间映射:

@javax.xml.bind.annotation.XmlSchema(
    namespace = "http://psi.eto.com/tsb/schema/servicecontract",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
    xmlns = {
        @javax.xml.bind.annotation.XmlNs(prefix = "ns2",
               namespaceURI="http://tsb.eto.com/terp/ws/schema"),

        @javax.xml.bind.annotation.XmlNs(prefix="ns3",
               namespaceURI="http://psi.eto.com/tsb/schema/project")
        // include the remaining namespace declarations
  )
)
package com.eto.psi.tsb.schema.servicecontract;

来源:JavaDoc for XmlSchema,示例 2。

请注意,仅当所有消息都具有完全相同的命名空间映射时,这才有效。


恕我直言,这应该只是一种解决方法。您应该敦促您的客户尽快调整正确的命名空间处理。

评论

0赞 fatherazrael 5/4/2021
谢谢。我已经给出了上面的命名空间,但有一个命名空间。它在末尾显示如下划线。有什么想法可以解决这个问题吗?xmlns:ns9=“psi.eto.com/kil/system/message” xmlns:ns9_=“psi.eto.com/tsb/schema/common">