java 网络服务测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6592833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Web Service testing
提问by Arvind
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.
我使用 JAX-WS 制作了 Web 服务。现在我想使用网络浏览器进行测试,但出现错误。有人可以解释我吗请帮忙。
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.
我将这个类作为简单的 Java 程序运行。
And I can see the WSDL in my browser at http://localhost:9191/webServiceTest?wsdl
.
我可以在浏览器中看到 WSDL 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.
我试图使用 URL 调用它http://localhost:9191/webServiceTest?sayHello?name=MKGandhi
,但我没有得到任何结果。
What is wrong here?
这里有什么问题?
采纳答案by phoenix.ru.smr
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);
}
}
回答by Micha
You try and test your webservice by using the url http://localhost:9191/webServiceTest?sayHello?name=MKGandhi
您尝试使用 url 来测试您的网络服务 http://localhost:9191/webServiceTest?sayHello?name=MKGandhi
Just try this url http://localhost:9191/webServiceTest/sayHello?name=MKGandhi
试试这个网址 http://localhost:9191/webServiceTest/sayHello?name=MKGandhi
it should work fine :)
它应该可以正常工作:)
回答by Amalan Dhananjayan
in your url "http://localhost:9191/webServiceTest?sayHello?name=MKGandhi"
try changing the localhostby your ip address.
example : "http://198.251.234.45:9191/webServiceTest?sayHello?name=MKGandhi"
在您的网址“http:// localhost:9191/webServiceTest?sayHello?name=MKGandhi”中,
尝试通过您的ip 地址更改localhost。
例如: “HTTP:// 198.251.234.45:?9191 / WebServiceTest的sayHello的名称= MKGandhi”