Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web服务测试_Java_Web Services_Jax Ws - Fatal编程技术网

Java Web服务测试

Java Web服务测试,java,web-services,jax-ws,Java,Web Services,Jax Ws,我使用JAX-WS创建了web服务。现在我想使用web浏览器进行测试,但我遇到了一个错误。有人能给我解释一下吗 我的服务级别: package another; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService(name = "WebService") public class WebServiceTest { public String sayHello(String name) {

我使用JAX-WS创建了web服务。现在我想使用web浏览器进行测试,但我遇到了一个错误。有人能给我解释一下吗

我的服务级别:

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);
    }
}
我将这个类作为简单的Java程序运行

我可以在
http://localhost:9191/webServiceTest?wsdl

我正试图使用URL
http://localhost:9191/webServiceTest?sayHello?name=MKGandhi
,但我没有得到任何结果


这里出了什么问题?

我无法告诉您为什么无法在浏览器中测试它。 但至少我可以告诉您如何从代码中测试它,因为您的Web服务可以工作:

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);
    }
}
在您的url“http://localhost:9191/webserviceetest?sayHello?name=MKGandhi”
尝试通过您的ip地址更改本地主机

示例:“http://198.251.234.45:9191/webserviceetest?sayHello?name=MKGandhi”

您尝试使用url
http://localhost:9191/webServiceTest?sayHello?name=MKGandhi

试试这个url
http://localhost:9191/webServiceTest/sayHello?name=MKGandhi

它应该可以正常工作:)