Arvind
Arvind

Reputation: 1237

Web Service testing

I made web services using JAX-WS. Now I want to test using a web browser, but I am getting an error. Can somebody explain me please help.

My Service class:

package another;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService(name = "WebService")
public class WebServiceTest {
    public String sayHello(String name) {
        return "Hello : " + name;
    }

    public static void main(String[] args) {
        WebServiceTest server = new WebServiceTest();
        Endpoint endpoint = Endpoint.publish(
                "http://localhost:9191/webServiceTest", server);
    }
}

I run this class as simple Java program.

And I can see the WSDL in my browser at http://localhost:9191/webServiceTest?wsdl.

And I am trying to call this using the URL http://localhost:9191/webServiceTest?sayHello?name=MKGandhi, but I am not getting any result.

What is wrong here?

Upvotes: 4

Views: 11952

Answers (3)

phoenix.ru.smr
phoenix.ru.smr

Reputation: 101

I can't tell you why it is not possible to test it in browser. But at least I can tell you how to test it from your code, cause your webservice works:

package another;

import javax.jws.WebService;

@WebService
public interface IWebServiceTest {
    String sayHello(String name);
}

package another;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class Main {
    public static void main(String[] args) throws Exception {
        String url = "http://localhost:9191/webServiceTest?wsdl";
        String namespace = "http://another/";
        QName serviceQN = new QName(namespace, "WebServiceTestService");
        Service service = Service.create(new URL(url), serviceQN);

        String portName = "WebServicePort";
        QName portQN = new QName(namespace, portName);

        IWebServiceTest sample = service.getPort(portQN, IWebServiceTest.class);
        String result = sample.sayHello("blabla");
        System.out.println(result);
    }
}

Upvotes: 2

Micha
Micha

Reputation: 11

You try and test your webservice by using the url http://localhost:9191/webServiceTest?sayHello?name=MKGandhi

Just try this url http://localhost:9191/webServiceTest/sayHello?name=MKGandhi

it should work fine :)

Upvotes: 1

Amalan Dhananjayan
Amalan Dhananjayan

Reputation: 2287

in your url "http://localhost:9191/webServiceTest?sayHello?name=MKGandhi"
try changing the localhost by your ip address.
example : "http://198.251.234.45:9191/webServiceTest?sayHello?name=MKGandhi"

Upvotes: 0

Related Questions