有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

两个WCF服务的java wsimport覆盖了objectFactory如何解决

抱歉,时间太长了。我是Java web服务的新手,一直在浏览web上的示例,以创建一个Java客户机,连接到一对由供应商应用程序托管的WCF服务。我可以分别为每个服务创建客户机,但当我尝试将它们放在一起时,第二个服务绑定会覆盖第一个服务绑定。我敢肯定是ObjectFactory类被覆盖了

我正在使用Metro(未安装在eclipse中)和以下ant内置的exclipse

建造。xml:

<project default="wsimport">
  <target name="wsimport">
    <exec executable="C:/Metro/bin/wsimport.bat"> 
        <arg line="-keep -s ../src -d ../bin -extension -Xnocompile -XadditionalHeaders -b ../build/wcf.jaxb -B-XautoNameResolution http://my.host.name/ptsqamt/Maintain/services/reports/2010/09/ReportServices.svc?singleWSDL"/>
    </exec>

    <exec executable="C:/Metro/bin/wsimport.bat"> 
        <arg line="-keep -s ../src -d ../bin -extension -Xnocompile -XadditionalHeaders -b ../build/wcf.jaxb -B-XautoNameResolution http://my.host.name/ptsqamt/Maintain/services/reports/2010/09/ReportFileService.svc?singleWSDL"/>
    </exec>
  </target>
</project>

连接到ReportFileService是可行的,但当我连接到ReportServices服务时,会出现以下异常:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://tempuri.org/}ReportServices is not a valid service. Valid services are: {http://tempuri.org/}ReportFileService

我曾尝试将构建放在单独的包中,这是可行的,但在运行时我遇到了类似的问题

我研究了各种线程,要么将目标名称空间从http://tempuri.org/更改为其他名称,要么将ObjectFactory类名更改为自定义名称

我有这个内联代码(找到here),但我不知道如何使用它/将其更改为外部文件

<xsd:complexType name="ObjectFactory">
  <xsd:annotation>
  <xsd:appinfo>
     <jxb:class name="ReportServicesObjectFactory" />
  </xsd:appinfo>
  </xsd:annotation>
</xsd:complexType>

有人能帮我解决这个问题吗


共 (1) 个答案

  1. # 1 楼答案

    好吧,我是个白痴

    将服务放在自己的包中最终解决了这个问题,但我在创建掩盖问题的服务时又犯了一个编码错误

    因为我将这些服务从一个环境移动到另一个环境(测试、阶段、生产),所以我使用外部定义的地址(对应于实际的测试、阶段和生产应用程序服务器地址)创建服务我剪切/粘贴了指向错误服务的URL,这就是下面的错误试图告诉我的

    Exception in thread "main" javax.xml.ws.WebServiceException: {http://tempuri.org/}ReportServices is not a valid service. Valid services are: {http://tempuri.org/}ReportFileService URL reportServicesAddress = null; URL reportFileServiceAddress = null;

        try {
            trustAllCertificates(); // For testing only
    
            reportFileServiceAddress = new URL("http://my.host.name/ptsqamt/Maintain/services/reports/2010/09/ReportFileService.svc");
            reportServicesAddress = new URL("http://my.host.name/ptsqamt/Maintain/services/reports/2010/09/ReportServices.svc");
        } catch (MalformedURLException e) {
    
            e.printStackTrace();
        }
    
        ReportServices rsProxy = connectToReportServices(reportServicesAddress);
        ReportFileService rfsProxy = connectToReportFileService(reportFileServiceAddress);
    

    获取互操作性信息对这件事来说是多么糟糕,所以我将传递一个小技巧,帮助解决我的问题

    wsimport在处理WSDL时会引发异常。只有当我将包参数添加到wsimport时,才会发生这种情况

    wsimport -p org.package.my myWSDL.xml

    我偶然发现一个博客,上面说在调用WCF服务时,建议将以下属性设置为false。您可以在我的wsimport-b wcf中看到它。jaxb

    wcf。jaxb

    <bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1">
      <globalBindings generateElementProperty="false"/>
    </bindings>
    

    这解决了这个问题,并在生成代码时停止了冲突