2011-09-05 67 views
2

我试图用wsimport创建Web服务代理,但由于冲突我得到一个错误。 “两个声明导致ObjectFactory类发生冲突。”Java EE Web服务:命名冲突

我有两个EJB,Webservices部署在一个耳朵。两者都有一个具有相同名称和参数的方法。每个WS都有自己的目标名称空间。

WS的SEI答:

@Local 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) 
@WebService(name = "AService", targetNamespace = "http://example.com/bla/a") 
public interface ASEI { 

    @WebMethod 
    @WebResult(name = "erpId") 
    public Long getId(@WebParam(name = "gid") 
    Long gid); 
} 

WebService的一个:

@Stateless 
@WebService(serviceName = "AWebService", 
     endpointInterface = "foo.endpointinterfaces.ASEI", 
     targetNamespace = "http://example.com/bla/a") 
@BindingType(SOAPBinding.SOAP12HTTP_BINDING) 
public class AWebService implements ASEI { 

    public Long getId(Long gid) { ... } 
} 

WS的SEI B:

@Local 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL,  parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) 
@WebService(name = "BService", targetNamespace = "http://example.com/bla/b") 
public interface BSEI { 

    @WebMethod 
    @WebResult(name = "erpId") 
    public Long getId(@WebParam(name = "gid") 
    Long gid); 
} 

web服务B:

@Stateless 
@WebService(serviceName = "BWebService", 
     endpointInterface = "foo.endpointinterfaces.ASEI", 
     targetNamespace = "http://example.com/bla/b") 
@BindingType(SOAPBinding.SOAP12HTTP_BINDING) 
public class BWebService implements BSEI { 

    public Long getId(Long gid) { ... } 
} 

当我将应用程序部署到Weblogic服务器时,第一个Webservices将导入WS B的xml声明并将它们用于消息类型。

A的WSDL:

<definitions targetNamespace="http://example.com/bla/a" name="AWebService" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://example.com/bla/a" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> 
<types> 
    <xsd:schema> 
     <xsd:import namespace="http://example.com/bla/b" schemaLocation="http://192.168.178.105:7001/BWebService/AWebService?xsd=1"/> 
    </xsd:schema> 
    <xsd:schema> 
     <xsd:import namespace="http://example.com/bla/a" schemaLocation="http://192.168.178.105:7001/AWebService/AWebService?xsd=2"/> 
    </xsd:schema> 
</types> 

<message name="getId"> 
    <part name="parameters" element="tns:getId"/> 
</message> 
... 

XSD = 1:

<xs:schema version="1.0" targetNamespace="http://example.com/bla/b" xmlns:tns="http://example.com/bla/b" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="getId" type="tns:getId"/> 
    <xs:complexType name="getId"> ... </xs:complexType> 
    ... 

XSD = 2:

<xs:schema version="1.0" targetNamespace="http://example.com/bla/a" xmlns:tns="http://example.com/bla/a" xmlns:ns1="http://example.com/bla/b" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:import namespace="http://example.com/bla/b" schemaLocation="http://192.168.178.105:7001/AWebService/AWebService?xsd=1"/> 
    <xs:element name="getId" nillable="true" type="ns1:getId"/> 
    ... 

有没有一种方式,每个WS定义了它自己的messagetypes?或者我还能做些什么来创建WS代理? (我不想将它们分成不同的Java EE应用程序。)

+0

克里斯,如果我的回答如下是有帮助的,它会如果您单击选中标记和“接受”它是正确的答案是凉爽。当你这样做的时候,我们都得到了Stackoverflow的声望点。 – twindham

回答

1

我想你可能会遇到类似的问题。但是,我不完全确定,所以这只是对答案的猜测。

我发现做了一些类自定义的绑定文件解决了我的问题,这些元素和复杂类型在多个模式中具有匹配的名称,这些名称在单个wsdl文件中引用,就像您在上面的示例中一样。

在XSD = 1你有

<xs:complexType="getId"> and <xs:element name="getId" ...> 

而且,在XSD = 2,你有

<xs:element name="getId" ...> 

因此,要解决这个问题我用这样的事情在我的装订文件夹...

<jxb:bindings version="2.0" 
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <jxb:bindings schemaLocation="http://192.168.178.105:7001/BWebService/AWebService?xsd=1" node="//xs:element[@name='getId']"> 
     <jxb:class name="getIdElement"></jxb:class> 
    </jxb:bindings> 
</jxb:bindings> 

这解决了我的问题,它有一个相同的名称为复杂类型元件。既然你有两个不同名字空间的xsd文件中的多个元素相同的名称,我甚至不知道这是否会帮助解决这个问题。

有关于可能的碰撞问题和他们的解决方案的更多信息在这里...http://goo.gl/vlQe3

好运, TW