【发布时间】:2011-11-01 12:39:13
【问题描述】:
我目前正在开发我的第一个 Web 服务。
客户端是用 JavaScript 开发的。
我的问题是它不起作用。我不知道我的问题是什么。
我认为这是客户网站上的错误。 我用 Java Web-Service Client 试了一下,效果很好。
网络服务:
import javax.jws.*;
import javax.jws.soap.SOAPBinding;
@WebService(name="TicketWebService", targetNamespace = "http://my.org/ns/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class TicketWebService {
@WebMethod(operationName="getContact")
public String getContact()
{
return "Hallo Hans!!!";
}
}
在服务器上发布:
import javax.swing.JOptionPane;
import javax.xml.ws.Endpoint;
public class PublishWsOnServer
{
public static void main( String[] args )
{
Endpoint endpoint = Endpoint.publish( "http://localhost:8080/services",
new TicketWebService() );
JOptionPane.showMessageDialog( null, "Server beenden" );
endpoint.stop();
}
}
客户:
<html>
<head>
<title>Client</title>
<script language="JavaScript">
function HelloTo()
{
var endpoint = "http://localhost:8080/services";
var soapaction = "http://localhost:8080/services/getContact";
xmlHttp = getXMLHttp();
xmlHttp.open('POST', endpoint, true);
xmlHttp.setRequestHeader('Content-Type', 'text/xml;charset=utf-8');
xmlHttp.setRequestHeader('SOAPAction', soapaction);
xmlHttp.onreadystatechange = function() {
alert(xmlHttp.responseXML);
}
xmlHttp.send(request);
}
</script>
</head>
<body onLoad="HelloTo()" id="service">
Body in Client
</body>
</html>
警报不起作用...
【问题讨论】:
-
你知道请求是否到达客户端吗?在服务中创建一些示例输出,例如System.out.println.
-
感谢您的回答...我在getContact()方法中写了一个system.out.println 输出应该放在哪里?我没找到...
-
输出应该在您启动 Java Web 服务的控制台中可用(main[] 方法)。
-
okey...de web-service 控制台中没有输出...您有什么想法吗?
标签: java javascript web-services jax-ws