简体   繁体   中英

CXF wsdl2java: No adress location in wsdl:port tag

When creating a web-service using CXF (configuration in Spring), my resulting WSDL is missing the address location in port tag. This is problematic for client side. If CXF is used for client creation, endpoint must be set programatically in client code. If Axis is used (the consumer of my web-service wants to be able to use Axis 1), there is an error saying

Error in generating Java from WSDL:  java.io.IOException: 
Emitter failure.  Cannot find endpoint address in port FooServiceSOAPPort 
in service FooServiceLocator

Instead of being forced to create the client using CXF or Axis2 and manually setting the endpoint in client code, I would like to have the following child element:

<soap:address location="http://localhost:9000/services/foo"/>

under the tag <wsdl:port binding="..." name="...> in my WSDL (generated by CXF from my service code).

If I save the WSDL as local file and I manually add the line above, client is generated without any problems using Axis, no manual endpoint setting is needed on the client side and everything is OK. So, how do I make the address location line appear in WSDL generated by CXF?

Here's my Spring config (relevant endpoint tag):

<jaxws:endpoint xmlns:hel="http://user.services/"
    name="Foo"
    address="/services/foo"
    implementor="services.foo.FooImpl"/>

Here's my service interface:

@WebService
public interface Foo {
    String method1(String arg1);
}

and implementation

@WebService(endpointInterface = "services.foo.Foo")
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public class FooImpl implements Foo {
    @WebMethod(operationName = "method1")
    public String method1(String arg1) {
        return "OK";
    }
}

My first question is how you are generating the WSDL file. Using Ant or Maven. If you are using Maven following will solve your problem.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-java2ws-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <id>process-classes</id>
                    <phase>process-classes</phase>
                    <configuration>
                        <className>com.stackoverflow.cxf.HelloWorld</className>
                        <genWsdl>true</genWsdl>
                        <verbose>true</verbose>
                        <address>http://localhost:9999/blah/blah</address>
                    </configuration>
                    <goals>
                        <goal>java2ws</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

in the <address> you can specify the one you want. If you are using java2ws command line tool (provided by cxf) you can specify the same using -address command line argument. CXF java2ws tool . I tried this using CXF version 2.5.9. generating sample web service and following is the snippet of resulting wsdl.

  <wsdl:service name="HelloWorldService">
    <wsdl:port name="HelloWorldPort" binding="tns:HelloWorldServiceSoapBinding">
      <soap:address location="http://localhost9999/blah/blah"/>
    </wsdl:port>
  </wsdl:service>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM