Web服务测试 [英] Web Service testing

查看:69
本文介绍了Web服务测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JAX-WS制作了Web服务.现在,我想使用Web浏览器进行测试,但出现错误.有人可以帮我解释一下吗?

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.

我的服务班级:

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程序运行.

I run this class as simple Java program.

我可以在浏览器的http://localhost:9191/webServiceTest?wsdl上看到WSDL.

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

我正在尝试使用URL http://localhost:9191/webServiceTest?sayHello?name=MKGandhi来调用它,但没有得到任何结果.

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

这是怎么了?

推荐答案

我无法告诉您为什么无法在浏览器中对其进行测试. 但是至少我可以告诉您如何从您的代码中对其进行测试,从而使您的网络服务正常运行:

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);
    }
}

这篇关于Web服务测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆