Search code examples
javaweb-serviceswebspherejax-wswebsphere-7

How to deploy multiple versions of the same web service on websphere


I want to support two versions of a web service on WebSphere 7. Although both web services work fine separately, only one is listening when both are present.

I package the following two classes and web.xml in the same war-file (inside an ear-file).

MyWebServiceV1Impl.java

package mywebservice._2015._01;

@WebService(name = "MyWebService", targetNamespace = "http://mywebservice.com/2015/01", portName = "MyWebServicePort", serviceName = "MyWebService")
public class MyWebServiceV1Impl implements MyWebService {
    // implementation of webmethods
}

MyWebServiceV2Impl.java

package mywebservice._2015._02;

@WebService(name = "MyWebService", targetNamespace = "http://mywebservice.com/2015/02", portName = "MyWebServicePort", serviceName = "MyWebService")
public class MyWebServiceV2Impl implements MyWebService {
      // implementation of webmethods
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <servlet>
    <display-name>WebService1</display-name>
    <servlet-name>WebService1</servlet-name>
    <servlet-class>mywebservice._2015._01.MyWebServiceV1Impl</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>WebService1</servlet-name>
    <url-pattern>v1</url-pattern>
  </servlet-mapping>

  <servlet>
    <display-name>WebService2</display-name>
    <servlet-name>WebService2</servlet-name>
    <servlet-class>mywebservice._2015._02.MyWebServiceV2Impl</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>WebService2</servlet-name>
    <url-pattern>v2</url-pattern>
  </servlet-mapping>
</web-app>

The web services are designed top down: starting from a wsdl. I'm thinking it has to do with the name of the web service but I can't figure out what to change so both services are listening when deployed without changing the name of the webservice in the wsdl.

I have also tried specifying the endpointInterface in the WebService-annotation but that didn't help either.

What am I missing?


Solution

  • You need to provide different serviceName. Try to change your second service annotation to: serviceName = "MyWebServiceV2". Remove these servlet and servlet-mapping entries from web.xml. Access your service via URLs: http://hostname/appName/serviceName.

    For your different servlet mappings to work services must at least differ in the portName, Check if you can have in the portName = "MyWebServicePort2" in the second implementation.

    The other solution is just to create 2 wars in one EAR.