如何使用wsdl2java

时间:2016-12-13 21:51:50

标签: java web-services wsdl wsdl2java javax

我正在使用Java来实现.NET Web服务的客户端。我对正确的做法有一些疑问,也是我需要解决的问题。

  1. 我正在使用maven和wsdl2java插件,它目前设置为从Web服务URL获取wsdl xml,我已经看到,大多数示例在项目源中使用wsdl的本地副本。有偏好吗?我发现你需要再次指定wsdl位置来实例化生成的服务类,有没有办法逃避它?
  2. 实例化服务对象时指定服务URL的方法是什么?目前,生成的代码会自动使用wsdl中指定的URL。我希望能够根据运行时变量更改地址。
  3. 我想设置一些配置,例如: WS-ReliableMessaging为true。这样做的最佳做法是什么?
  4. 这是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>
    

    以下是我当前如何实例化服务对象:

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

0 个答案:

没有答案