2

我正在尝试使用 wsimport 创建 Web 服务代理,但由于冲突而出现错误。“两个声明导致 ObjectFactory 类发生冲突。”

我在一只耳朵中部署了两个带有 Web 服务的 EJB。两者都有一个具有相同名称和参数的方法。每个 WS 都有自己的目标命名空间。

WS A 的 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);
}

网络服务 A:

@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 B的SEI:

@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);
}

网络服务 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 服务器时,第一个 Web 服务会导入 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 定义它自己的消息类型?或者我还能做什么来创建 WS 代理?(我不想将它们分成不同的 Java EE 应用程序。)

4

1 回答 1

1

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

我发现进行了一些类自定义的绑定文件解决了我的问题,这些元素和 complexTypes 在单个 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> 

这解决了我的complexTypeelement具有相同名称的问题。由于您在具有不同名称空间的两个 xsd 文件中的多个元素具有相同的名称,因此我什至不确定这是否有助于解决该问题。

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

祝你好运,台湾

于 2012-02-03T17:06:48.427 回答