2

Sorry, this is long. I'm new to Java web services, and have been moving through examples on the web to create a Java client to a pair of WCF services hosted by a vendor application. I am able to create the client for each separately, but when I try and put them together, the second service bindings overwrite the first. I'm pretty sure it's the ObjectFactory class that's getting overwritten.

I'm using Metro (not installed in eclipse) and the following ant build in 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>

Connecting to the ReportFileService works, but when I connect to the ReportServices service, I get the following exception:

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

I have tried to put the build's in separate packages, which works, but I get a similar issue at runtime.

I have looked at various threads, to either change the target name space from http://tempuri.org/ to something else, or change the ObjectFactory class name to something custom.

I have this inline code (found here), but I don't know how to use it / change it to an external file.

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

Can anyone help on how I can resolve this.

Community
  • 1
  • 1
Mike
  • 3,186
  • 3
  • 26
  • 32

1 Answers1

0

Okay, I'm an idiot...

Placing the services in their own package is what ultimately solved the issue, but I made an additional coding error when creating the service that was masking the issue.

Because I move these services from environment to environment (test, stage, production), I create the service using an externally defined address (corresponding to the actual test, stage and production app server addresses). I cut/paste the URL which had pointed to the wrong service, which is what the below error was trying to tell me.

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

It's crazy how bad getting interoperability information is for this, so I'll pass along a small tip that helped solve my issue.

wsimport would throw an exception when processing the WSDL. This only happened when I added the package parameter to my wsimport.

wsimport -p org.package.my myWSDL.xml

I stumbled upon a blog that said when calling WCF services, it's recommended to set the following property to false. You can see it in my wsimport -b wcf.jaxb

wcf.jaxb

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

This resolved that issue, and stopped the conflicts when generating the code.

Mike
  • 3,186
  • 3
  • 26
  • 32