2

I am using Java to implement a client for a .NET web service. I've got some questions about the right practices and also a problem that I need solution for.

  1. I am using maven and the wsdl2java plugin, it is currently set to get the wsdl xml from the web service url, I've seen though that most examples use a local copy of wsdl in the project source. Is there a preference? I've found as well that you need to specify the wsdl location again to instantiate the generated service class, is there a way to escape that?
  2. What is the way to specify the service URL when instantiating the service object? Currently the generated code automatically use the URL that is specified in wsdl. I'd like to be able to change the address based on runtime variables.
  3. I'd like to set some configuration like for e.g. WS-ReliableMessaging to true. What is the best practice to do that?

Here is the plugin in POM:

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>${cxf.version}</version>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>http://ServerNameA/FooService.svc?wsdl</wsdl>
            <serviceName>FooService</serviceName>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
</plugin>

And here is how I currently instantiate the service object:

FooService fooService = new FooService(new URL("http://ServerNameA/FooService.svc?wsdl"));
IFooService service = fooService.getWSHttpBindingIFooService();
service.getData(); // Calling one of the ports/service methods
Bishoy
  • 705
  • 9
  • 24

0 Answers0