title: WebFault and Web Service in different namespaces
body: <p>I need to define custom exception in different namespace than a web service. But when I generate a wsdl, some wrapper appears in the namespace of webservice. Is it possible to use exception from another namespace without this wrapper?</p>
  
  <p>Exception:</p>
  
  <pre><code>@WebFault(targetNamespace = "http://somenamespace/server/faults",
  faultBean = "my.package.SoapBadRequestException.FaultBean")
      public class SoapBadRequestException extends Exception {
      private FaultBean faultBean;
  
      @XmlType(name = "FaultBean", namespace = "http://somenamespace/server/faults")
      public static class FaultBean {}
  
      public SoapBadRequestException() { super(); }
  
      public SoapBadRequestException(String message, FaultBean faultBean, Throwable cause) {
          super(message, cause);
          this.faultBean = faultBean;
      }
  
      public SoapBadRequestException(String message, FaultBean faultBean) {
          super(message);
          this.faultBean = faultBean;
      }
  
      public FaultBean getFaultInfo() { return faultBean; }
  }
  </code></pre>
  
  <p>Web service:</p>
  
  <pre><code>@WebService(targetNamespace = "http://somenamespace/server/ws")
  public interface MyWebService {
  
  void someOperation(
          @WebParam(name = "param1") String param1,
          @WebParam(name = "param2") String param2) throws SoapBadRequestException;
  }
  </code></pre>
  
  <p>Resulting wsdl (FaultBean is undefined, also don't know why):</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
                xmlns:tns="http://somenamespace/server/ws" 
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
                xmlns:ns1="http://somenamespace/server/faults" 
                name="MyWebServiceImpl" 
                targetNamespace="http://somenamespace/server/ws"&gt;
  &lt;wsdl:types&gt;
      &lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                  xmlns:tns="http://somenamespace/server/faults" 
                  attributeFormDefault="unqualified" 
                  elementFormDefault="unqualified" 
                  targetNamespace="http://somenamespace/server/faults"&gt;
          &lt;xsd:element name="SoapBadRequestFault" nillable="true" type="tns:FaultBean"/&gt;
      &lt;/xsd:schema&gt;
      &lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                  xmlns:tns="http://somenamespace/server/ws" 
                  attributeFormDefault="unqualified" 
                  elementFormDefault="unqualified" 
                  targetNamespace="http://somenamespace/server/ws"&gt;
          &lt;xsd:element name="someOperation" type="tns:someOperation"/&gt;
          &lt;xsd:complexType name="someOperation"&gt;
              &lt;xsd:sequence&gt;
                  &lt;xsd:element name="param1" type="xsd:string"/&gt;
                  &lt;xsd:element name="param2" type="xsd:string"/&gt;
              &lt;/xsd:sequence&gt;
          &lt;/xsd:complexType&gt;
          &lt;xsd:element name="someOperationResponse" type="tns:someOperationResponse"/&gt;
          &lt;xsd:complexType name="someOperationResponse"&gt;
              &lt;xsd:sequence/&gt;
          &lt;/xsd:complexType&gt;
      &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name="someOperationResponse"&gt;
      &lt;wsdl:part element="tns:someOperationResponse" name="parameters"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  
  &lt;!-- This is the redundant wrapper in the web service namespece --&gt;
  &lt;wsdl:message name="SoapBadRequestException"&gt;
      &lt;wsdl:part element="ns1:SoapBadRequestFault" name="SoapBadRequestException"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="someOperation"&gt;
      &lt;wsdl:part element="tns:someOperation" name="parameters"&gt;&lt;/wsdl:part&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="MyWebService"&gt;
      &lt;wsdl:operation name="someOperation"&gt;
          &lt;wsdl:input message="tns:someOperation" name="someOperation"&gt;&lt;/wsdl:input&gt;
          &lt;wsdl:output message="tns:someOperationResponse" name="someOperationResponse"&gt;&lt;/wsdl:output&gt;
          &lt;wsdl:fault message="tns:SoapBadRequestException" name="SoapBadRequestException"&gt;&lt;/wsdl:fault&gt;
      &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="MyWebServiceImplSoapBinding" type="tns:MyWebService"&gt;
      &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
      &lt;wsdl:operation name="someOperation"&gt;
          &lt;soap:operation soapAction="" style="document"/&gt;
          &lt;wsdl:input name="someOperation"&gt;
              &lt;soap:body use="literal"/&gt;
          &lt;/wsdl:input&gt;
          &lt;wsdl:output name="someOperationResponse"&gt;
              &lt;soap:body use="literal"/&gt;
          &lt;/wsdl:output&gt;
          &lt;wsdl:fault name="SoapBadRequestException"&gt;
              &lt;soap:fault name="SoapBadRequestException" use="literal"/&gt;
          &lt;/wsdl:fault&gt;
      &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name="MyWebServiceImpl"&gt;...&lt;/wsdl:service&gt;
  </code></pre>
  
  <p></p>
  
  <p>I saw <a href="https://stackoverflow.com/questions/11452144/define-webfault-in-a-different-namespace-package-than-the-service-one-using-c">this</a> and <a href="https://stackoverflow.com/questions/27964771/why-webservices-wsdl-is-not-using-the-webfault-namespace?noredirect=1#comment59747195_27964771">this</a> but nothing helped.</p>