为什么Webservice的WSDL没有使用@WebFault命名空间?

时间:2015-01-15 13:41:31

标签: java web-services wsdl jax-ws

在我的场景中,我有两个Web服务:

package com.ws.mywebservice1;
...
@Webservice(serviceName = "MyWebservice1", targetNamespace="http://some.custom.namespace1/MyWebservice1")
@Stateless
@LocalBean
@HandleChain(file = "handlers.xml")
public class MyWebservice1 extends AbstractWebService {
  @WebMethod
  @WebResult(name = "outMyResult1", targetNamespace="http://some.custom.namespace1/MyWebservice1")
  public OutMyResult1 myMethod() throws ApplicationFault {
  }
}

package com.ws.mywebservice2;
...
@Webservice(serviceName = "MyWebservice2", targetNamespace="http://some.custom.namespace2/MyWebservice2")
@Stateless
@LocalBean
@HandleChain(file = "handlers.xml")
public class MyWebservice2 extends AbstractWebService {
  @WebMethod
  @WebResult(name = "outMyResult2", targetNamespace="http://some.custom.namespace2/MyWebservice2")
  public OutMyResult2 myMethod() throws ApplicationFault {
  }
}

两者共享相同的ApplicationFault例外:

package com.ws.exceptions;
...
@WebFault(name="ApplicationFault", targetNamespace="http://ws.exceptions.com/ApplicationFault")
@ApplicationException(rollback = true)
@XmlType(name="ApplicationFault", namespace="http://ws.exceptions.com/ApplicationFault")
public class ApplicationFault extends Exception {
  private Status status;
  ...
}

生成的MyWebservice2的WSDL使用MyWebservice1的命名空间来声明ApplicationFault

<!-- WSDL -->
<xsd:import namespace="http://some.custom.namespace1/MyWebservice1" schemaLocation="http://localhost:7001/my-app/1.0.0-SNAPSHOT/MyWebservice2?xsd=2"/>

<!-- XSD -->
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.8-b13937 svn-revision#13942. -->
<xsd:schema xmlns:ns1="http://ws.exceptions.com/ApplicationFault" xmlns:ns0="http://some.custom.namespace1/MyWebservice1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://some.custom.namespace1/MyWebservice1"> namespace="http://ws.exceptions.com/ApplicationFault"/>
  <xsd:complexType name="ApplicationFault">
    <xsd:sequence>
      <xsd:element name="message" type="xsd:string" minOccurs="0"/>
      <xsd:element name="status" type="ns1:Status" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

为什么生成的WSDL使用了错误的命名空间,而忽略了@WebFault targetNamespace?

0 个答案:

没有答案