22

I built a minimal web service and published it using javax.xml.ws.Endpoint. If I try to get the WSDL at http://localhost:1234/AddService?wsdl it works fine.

Trying to recieve it at http://192.168.0.133:1234/AddService?wsdl, I don't receive anything. This address is the same as localhost.

Is there a posibiility to publish a webservice without providing the address?

package test;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class AddService {

    @WebMethod
    public int add(int a, int b){
        return a+b;
    }

    public static void main(String[] args ){
        Endpoint.publish("http://localhost:1234/AddService", new AddService());
    }
}

Changing the code to

Endpoint.publish("http://192.168.0.133:1234/AddService", new AddService());

gets me the wsdl on the IP address but not on localhost.

Isn't there a posibility to just define the port?

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
daniel
  • 3,166
  • 2
  • 17
  • 18

2 Answers2

40

Could you try publishing it on 0.0.0.0?

ivy
  • 5,539
  • 1
  • 34
  • 48
  • 2
    This works. localhost, 0.0.0.0 and 192.168.0.133 gets me the wsdl. But why doesn't it, while publishing on localhost or the other ip. – daniel Sep 09 '10 at 22:40
  • 3
    Happy to hear it works. localhost is ip 127.0.0.1 , and Endpoint.publish (obviously) only binds to the provided address. With 0.0.0.0 you tell it to 'listen' to incoming connections to any ip-address (associated with your computer). It can be a handy feature to only bind to a specific ip-address, e.g. if you want your service to be only available to a certain subnet... – ivy Sep 17 '10 at 07:13
  • Great trick. Is this officially supported or just a handy side-effect? – Thorbjørn Ravn Andersen Aug 22 '11 at 12:55
  • 3
    It's an 'official way', but why it works is a matter of ipv4 specification; check http://en.wikipedia.org/wiki/IPv4 or questions on stackoverflow on this subject : http://stackoverflow.com/search?q=0.0.0.0 – ivy Sep 05 '11 at 09:27
  • 2
    What would the equivalent be for IPv6? – Thorbjørn Ravn Andersen Jun 19 '12 at 12:13
  • I have couple of questions. 1) The publish method of Endpoint, takes a URL to bind to but the URL changes from environment to environment. So, dynamically constructing the path is the best way or is there any other best practice. 2) My current project runs on IBM WAS8.5.5,and the JAX-WS annotated classes are automatically scanned. So, when should one use Endpoint publish method. – S R Chaitanya Sep 11 '18 at 06:51
  • Amazing how the question makes the answer, where many other answers are actually questions. – 9ilsdx 9rvj 0lo Jun 06 '19 at 14:16
-2

Here is my code:

Endpoint.publish("http://localhost:8080", new ServiceController());

It says The address's path should start with /

sachJuve
  • 59
  • 1
  • 6