首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java和Soap Web Service |为什么迁移时名称空间前缀会自动从ns2更改为ns4?

Java和Soap Web Service |为什么迁移时名称空间前缀会自动从ns2更改为ns4?
EN

Stack Overflow用户
提问于 2021-05-04 00:56:37
回答 1查看 120关注 0票数 0

Soap服务迁移更改web服务响应上的命名空间前缀:

之前是这样的:

代码语言:javascript
复制
<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">

现在它将更改为:

代码语言:javascript
复制
<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">

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

代码语言:javascript
复制
@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)

Package Info中的所有ns都是这样的:

代码语言:javascript
复制
@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,但没有所需的结果。

原因:客户有未准备更改的旧代码和硬编码的命名空间。

EN

回答 1

Stack Overflow用户

发布于 2021-05-04 01:43:30

您可能可以使用Package Info完全修复名称空间映射:

代码语言:javascript
复制
@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。

请注意,只有当所有消息都具有完全相同的名称空间映射时,此方法才有效。

我想这应该只是一种变通方法。您应该敦促您的客户尽快调整正确的命名空间处理。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67372844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档