我正在使用 Glassfish 编写一个(非常)小的 SOAP Web 服务。我的代码如下:
毫秒.java
package com.suture.self.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public interface Milliseconds {
@WebMethod
String currentMilliseconds();
}
MillisecondsImpl.java
package com.suture.self.ws;
import javax.jws.WebService;
@WebService(endpointInterface = "com.suture.self.ws.Milliseconds")
public class MillisecondsImpl implements Milliseconds {
@Override
public String currentMilliseconds() {
return String.valueOf(System.currentTimeMillis());
}
}
MillisecondsEndpoint.java
package com.suture.self.ws;
import javax.xml.ws.Endpoint;
public class MillisecondsEndpoint {
public static void main(String[] args) {
Endpoint.publish("http://sutureself.com:9292/ws/milli", new MillisecondsImpl());
}
}
当我在 Glassfish 服务器上(通过 Eclipse)运行此程序时,管理控制台会向我显示通常工作的 ?wsdl
和 ?Tester
端点,但不是我想要的端点。已经创造出来了。在浏览器中点击该 URL ( http://sutureself.com:9292/ws/milli ) 也会返回“无法连接”错误。
如果我选择“启动”,则会显示两个链接(Glassfish 中的每个 http 端口一个链接),但这些链接会返回 404。
如果我只是尝试点击“上下文根”路径,那也是行不通的。我需要一个入口点,但我找不到它。
我错过了什么?
请注意!上面代码中的所有 sutureself.com
实际上都是 localhost
,所以显然不喜欢您使用 localhost 发布 URL。
我们很乐意添加有关如何配置我的设置的更多信息。
最佳答案
我之前也在 SOAP WS 中做过一个示例,但我有一个疑问,为什么你使用 Glassfish Server 因为你正在通过 main 方法部署你的 WS,该方法会将地址与你的服务绑定(bind)。我认为不需要服务器。
只需按照以下步骤使用 eclipse 来测试 WS-
注意:请关闭您的 Glassfish 服务器
1-创建一个新的java项目(不是动态Web项目)
2-在hello包中创建HelloWorld类
package hello;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class HelloWorld{
@WebMethod
public String method(String name)
{
return "hello " +name;
}
}
您不需要显式地创建接口(interface)。
3:现在创建一个Publisher类来发布hello包中的WebService
package hello;
import javax.xml.ws.Endpoint;
public class Publisher {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Endpoint.publish("http://LH.com:9292/ws/milli", new HelloWorld());
}
}
现在您已经将您的 WS 绑定(bind)到 http://LH.com:9292/ws/milli 。通过http://LH.com:9292/ws/milli?wsdl查看或http://LH.com:9292/ws/milli?test
关于java - JAX-WS 端点不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22687115/