【问题标题】:wsimport of two WCF services overwrites objectFactory - how to resolve两个 WCF 服务的 wsimport 覆盖 objectFactory - 如何解决
【发布时间】:2015-09-04 07:35:34
【问题描述】:

对不起,这很长。我是 Java Web 服务的新手,并且一直在浏览 Web 上的示例,以创建一个 Java 客户端到由供应商应用程序托管的一对 WCF 服务。我可以分别为每个客户端创建客户端,但是当我尝试将它们放在一起时,第二个服务绑定会覆盖第一个。我很确定是 ObjectFactory 类被覆盖了。

我正在使用 Metro(未安装在 Eclipse 中)和以下 ant 构建在 exclipse 中。

build.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 服务时,出现以下异常:

线程“主”javax.xml.ws.WebServiceException 中的异常: {http://tempuri.org/}ReportServices 不是有效的服务。有效的 服务是:{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>

谁能帮我解决这个问题。

【问题讨论】:

    标签: java xml web-services jaxb


    【解决方案1】:

    好吧,我是个白痴……

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

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

    线程“主”javax.xml.ws.WebServiceException 中的异常: {http://tempuri.org/}ReportServices 不是有效的服务。有效的 服务是:{http://tempuri.org/}ReportFileService URL reportServicesAddress = null; 网址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>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多